May 21, 2015

Automate install and setup of RVM/Ruby with Compass/Sass in Vagrant

My teams use development environments powered by Vagrant, which I highly recommend. This however requires we either maintain or manage a variety of recipes/cookbooks, or that we bootstrap our dev virtual machines identically. I generally prefer the latter to avoid issues with connecting to Chef that have burned me in the past, or just general third-party woes. Bootstrapping an app then requires some scripting to properly setup Ruby and thereby Compass and Sass gems which we use for compiling our assets. That being said, we’ve chosen to use RVM instead of rbenv or any of the alternatives just because it suits us best. I’m not evangelical one way or the other….

May 20, 2015

Update User Entity on login

I recently built an app that required we update the authenticated user’s lastOnlineDate every session so we can quickly track who has been online in the last interval of time. We set this interval as a parameter and used that to avoid hitting the database more than absolutely necessary to accomplish this. To make it work, we needed to leverage onSecurityInteractiveLogin: app/config/parameters.yml

MyApp/EventListener/LoginListener.php

  app/config/services.yml

Alternatives In this particular use-case, leveraging a setContainer call may not be necessary if all you’re doing is setting a single value on a User entity. Alternatively, we could simply send the activity_minutes parameter as an argument to the service, and not use…

May 19, 2015

Multiple dynamic EntityManagers in Symfony2

Symfony2 is fantastic when coupled with Doctrine, but unfortunately Doctrine has its limitations and does not inherently support dynamic EntityManager connections, because the parameters for each connection must be defined and loaded at the kernel level. This assumes that each of the connections have an identical schema mapped by Doctrine2. My live implementation functions for a single/multi tenant shared architecture in which connection parameters are encrypted and housed in MasterDatabase, while ChildDatabase1, ChildDatabase2, all have the exact same schema, but isolated data for a variety of business reasons. There are several components to making this work: app/config/parameters.yml app/config/config.yml app/config/services.yml MyApp/Services/ApplicationConnector.php app/config/parameters.yml

app/config/config.yml

app/config/services.yml

MyApp/Services/ApplicationConnector.php

Usage in a Controller…