June 18, 2015

Rebase your database migrations to a single class file quickly

While developing, Doctrine Migrations can quickly become obsolete as you adjust your schema in the early stages of development. Nevertheless, Migrations are still a vital part of properly building compatibility for deployments. However, to consolidate and avoid having several (or in my case dozens) Migration Versions before you’ve got a stable schema, I’ve found it very useful to “rebase” my migrations to a single file. I also try to keep my non entity driven schemas in a separate file, typically Version0.php. All of my recent development work has been on Symfony 2.7 so I have a modified sessions table I use for PDO session management (that’s a separate debate we can have later)….

June 16, 2015

Throw Exception based on Accept Header

Symfony has a wonderful onKernelException event that we can expose in an Event Listener to properly handle exceptions in our applications. In one particular use case, we want to handle JSON and XML responses for our exceptions that are thrown via our API. In this case, we need to format and render our exception based on the Accept Header of the initial request. This is handled in two simple steps: An ApiExceptionListener class that processes the onKernelException event. A service declaration that tells the Symfony kernel about our Event Listener. The Exception Listener

We need to be careful above not to check the Accept header for XML because some browsers will…

June 15, 2015

Symfony3 Restructuring

Symfony3 is coming soon and with it a handful of wonderful changes and restructuring to the core directory structure of a symfony app. The new directory structure has a number of benefits, all of which are minor and may require minimal changes to your workflow. PHPUnit phpunit can now be run from the project root without having to explicitly specify the path of the configuration file.

Binary Executables All binary executable files are now all located in a single location – the bin directory. This simplifies things also so on a *NIX machine you can configure your $PATH to simplify calling repeatable commands.

A new /var directory The new /var…