We’ve recently been racking our brains over possible ways to keep a PHP Framework we’ve been developing, agile within individual projects. The Framework is still quite young development wise, but it is mature enough to develop sites on. So ideally what we wanted to do was create a Git repository for our Framework under a organization account on the lovely Github. Once done, the tricky part was trying to separate the framework code from the individual sites code.
This was quite interesting because what it would enable us to do is continuously develop and push changes to our framework from each and every individual site we make separate from the core Controllers, Models and Views of the individual sites / projects that the Framework was deployed on.
To help visualize this here is an example directory structure of the framework.
We’re fairly new to Git and having used SVN in the past, it was quite a jump, however we’re pretty in love with Github and the whole approach. So naturally we decided we had to make this work, after a few days of brain racking and scrobbling the two choices became evident.
Due to the application folder being ignored by the frameworks repository, you can then ‘init’ a new git repository inside the application folder and work on your site completely separate from the framework and commit, pull and push as you wish without effecting the cloned framework. Whats also handy is you could if you so wanted add changes to the framework and push them right to the main repository which also works well for us when the framework is still very much in development.
The second approach was to utilise the advantage that our Framework can be installed into sub directories and thus we can specify the location of our core folder, right in our index.php file. This would allow us to make our directory structure relatively similar to that of before, but something more like this.
Now what we would do here is set in our config within the application folder
define('EXT', '.php'); define('DS', DIRECTORY_SEPARATOR); define('ROOT', dirname(dirname(__FILE__)).'/Fury-PHP/'); # this is the important line define('SYS', 'lib/core/');
Now onto the important thing, we would Git init in the root but add the Framework into lib via git submodules, this would allows us to manage the source of the Framework right to its main repository but also allow us to commit and update the submodule without effecting our application instance. The only problem being you now would need a index.php and .htaccess file added per application, which isn’t such a bad thing in fairness.
We’ve not decided what approach we prefer the most, so we’re most likely in true testing practices going to try out both methods putting them to use in real life examples and see how we go from there.
We might post a follow up to this post to let you all know how we get on. Nevertheless we hope this post might be helpful to anyone running a similar Framework and wanting to continuously improve and develop it across multiple websites and projects.