Autoloading ZF1 apps in Apigility
This is a procedure I write to autoload a ZF1 project into a ZF2 based application, using Apigility as an example.
- PHP 5.4 or higher
- A ZF1 project, I'm using my demo application zfdemo as example
- An IDE
To install composer, please use the following command on your command line
php -r "readfile('https://getcomposer.org/installer');" | php
Step 1: Get the Apigility project
The easiest way to get started with Apigility is to install it using Composer. I call my project "zf-apigility, but you can choose any name you want.
cd /path/to/workspace php composer.phar create-project -sdev zfcampus/zf-apigility-skeleton zf-apigility
When Composer asks you "Do you want to remove the existing VCS (.git, .svn..) history? [Y,n]?", I choose "Y" as I want to maintain my own repo for my Apigility usage.
NOTE: Don't forget to enable "development" mode for Apigility!
cd zf-apigility php public/index.php development enable
In order to track our changes, we initialise this project as a GIT project.
git init git add . git commit -m 'Initial commit of Apigility project (see https://github.com/zfcampus/zf-apigility-skeleton/blob/master/README.md for more information)'
Step 2: Adding your ZF1 project to Apigility
As example we use the zfdemo ZF1 application, which already contains a couple of modules with models, services, forms and so on. The easiest way to include it in our application is to add it as a GIT Submodule and put it in our "vendor" directory, even though we're not managing it through Composer.
git submodule add -f https://github.com/in2it/zfdemo.git vendor/zfdemo
We use the
-f option to force installing it in our vendor directory, which is ignored by GIT. We need to add the following line to our
.gitignore file to ensure GIT fetches updateds from this project if they occur.
Now GIT tracks changes from the main zfdemo application. Commit the changes and get ready to bootstrap the stuff.
git commit -am 'Including ZF1 project as GIT Submodule'