Skip to content

Instantly share code, notes, and snippets.

@DragonBe
Last active August 29, 2015 13:57
Show Gist options
  • Save DragonBe/9385870 to your computer and use it in GitHub Desktop.
Save DragonBe/9385870 to your computer and use it in GitHub Desktop.
Procedure to autoload ZF1 applications in Apigility

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.

Requirements

  • PHP 5.4 or higher
  • A ZF1 project, I'm using my demo application zfdemo as example
  • Composer
  • 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.

!vendor/zfdemo

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'

Step 3: Start bootstrapping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment