Symfony and svn:externals... super-slick the easy way

Ethan's picture

(If you already know about Symfony and just want to use svn:externals to install it, you might want to skip here)

We've begun using the Symfony MVC framework for some small projects and really getting into it. If you're not familiar with MVC frameworks, then...well, you probably are more familiar than you know: the MVC patternis the design pattern at the heart of well-known development frameworks like Rails and Django. PHP has its own varieties of MVC frameworks, and Symfony ranks along with other popular options such as CakePHP and Code Igniter.

Like most MVC frameworks, a large part of what makes Symfony such a powerful tool is it's meticulously organized codebase. Placement of each piece of the stack is exquisitely thought-out, providing the foundation for an extensive plugin-architecture capable of interfacing with and incorporating numerous third-party libraries and tools. Like any intricate protocol, however, the organization of Symfony's code can be somewhat daunting and labyrinthine, contributing to its fairly steep learning curve.

Luckily there are some great tutorials and references out there, including the freely available version of the commercially published Symfony Book, the Getting Started Guide and a bunch more.

Probably the most useful of the available materials is the Jobeet Practical Symfony "24-day" tutorial. This toot covers everything from the basics of setting up a Symfony site to advanced Ajax, deployment and internationalization topics. One really useful trick which is not fully explained in the Jobeet tutorial, however, is the use of the svn:externals property to include the full Symfony codebase in your project and make updating a snap.

As a bit of background, there are a few ways you can install Symfony: many install the files as shared libraries via either PHP's Pear tool or package managers like apt-get or port. This provides a single copy of the Symfony libraries which all of you web apps can then share and build off of. For most web projects, however, it's ideal to include all the code needed to run your site in a single repository, as that makes collaboration easier, ensures standardization across web servers and development environments and generally reduces the risks of mix-ups and messes.

For this reason, the Jobeet tutorial recomments that users install Symfony as 3rd party vendor code of it's own in your project, in the directory lib/vendor/symfony.

It turns out that this approach works extremely well with the svn:externals property, but it takes a little bit of figuring out to get it working just so. The basic approach is mentioned in the official Symfony docs, but it took a bit of experimenting and the help of a very useful blog post and the Subversion book's chapter on Externals to get it working.

Here's a step-by-step "getting started with Symfony" process which emerged:

  1. Create your new Subversion repository for your new project and check out either Trunk or a starter development branch.
  2. In your working copy, create the directory "lib/vendor" and add it to your repo.
  3. Now for the magic of svn externals. The first thing we're going to do is set the property "svn:externals" on lib/vendor to tell it to load the Symfony files from the 1.2 branch into a directory named "symfony". We do this by executing the following line of code:
     svn propset svn:externals "symfony http://svn.symfony-project.com/tags/RELEASE_1_2_8" lib/vendor
    Two notes on this: you'll need to change this to "svn propedit svn:externals ..." if you have more than one external in a given directory, and you may want to change the tag to a more recent release or, if you're really daring, to the bleeding-edge development branch of the Symfony version you're installing.
  4. Now for magic part two: svn up and watch as subversion automagically pulls in all the code for Symfony, and in turn all the externals which Symfony itself includes. In one step you're downloading a bunch of projects, each of which might be on their own server.
  5. Once this is done you can svn commit and then pretty much continue generating your project, adding files, etc. as the Jobeet tutorial recommends. Then, when it's time to update your Symfony version, just edit that svn:extnerals property to point to the new tag, svn up and follow the upgrade instructions....easy as pie!

The next step is going to be installing plugins via svn externals. Anyone have any experience comparing the "./sympfony plugin:install" action with manually downloading via svn:externals?

Comments

Thom Porter's picture

I found this quite helpful! Travis' reply is nice to see to, thanks to both!

Anonymous's picture

How do I make 'lib' a working copy in svn?

Ethan's picture
Member since:
12 July 2007
Last activity:
1 week 4 days

After you've committed your new symfony project to svn and checked it out, the entire checked-out project directory is the working copy.