From 7ac195f6bdd98a9d64c58bfc79fd885c2f489c88 Mon Sep 17 00:00:00 2001 From: Evan Coury Date: Wed, 13 Jun 2012 15:42:12 -0700 Subject: [PATCH] Update index.php and Application\Module to make composer use optional - index.php now supports ZF2_PATH env var or git submodule - re-add the git submodule to make non-composer install easier - update the readme - use include instead of include_once, see: http://robert.accettura.com/blog/2011/06/11/phps-include_once-is-insanely-expensive/ If you are not using composer, you no longer have to make changes to the default skeleton. --- .gitmodules | 6 +++--- README.md | 29 +---------------------------- composer.json | 2 +- module/Application/Module.php | 11 +++++++++++ public/index.php | 22 +++++++++++++++------- vendor/ZF2 | 1 + 6 files changed, 32 insertions(+), 39 deletions(-) create mode 160000 vendor/ZF2 diff --git a/.gitmodules b/.gitmodules index 8f630ff..040b52e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "vendor/ZendFramework"] - path = vendor/ZendFramework - url = git://github.com/zendframework/zf2.git +[submodule "vendor/ZF2"] + path = vendor/ZF2 + url = https://github.com/zendframework/zf2.git diff --git a/README.md b/README.md index dd9072b..4e7d164 100644 --- a/README.md +++ b/README.md @@ -23,37 +23,10 @@ and use composer to install dependencies: Using Git submodules -------------------- -Alternatively, you can install using native git submodules. This method works fine but it is -recommended that you use Composer due to the dependency management it provides. +Alternatively, you can install using native git submodules: git clone git://github.com/zendframework/ZendSkeletonApplication.git --recursive -You will also need to update public/index.php and modules/Application/Module.php to enable autoloading. -For public/index.php, replace lines 2-13 with: - - use Zend\Loader\AutoloaderFactory, - Zend\ServiceManager\ServiceManager, - Zend\Mvc\Service\ServiceManagerConfiguration; - - chdir(dirname(__DIR__)); - require_once (getenv('ZF2_PATH') ?: 'vendor/ZendFramework/library') . '/Zend/Loader/AutoloaderFactory.php'; - - // Setup autoloader - AutoloaderFactory::factory(); - -Within modules/Application/Module.php add this method to the Application class: - - public function getAutoloaderConfig() - { - return array( - 'Zend\Loader\StandardAutoloader' => array( - 'namespaces' => array( - __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, - ), - ), - ); - } - Virtual Host ------------ Afterwards, set up a virtual host to point to the public/ directory of the diff --git a/composer.json b/composer.json index 1d6bc58..86591c3 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "homepage": "http://framework.zend.com/", "require": { "php": ">=5.3.3", - "zendframework/zendframework": "dev-master#c1273a4ea7ab16ecb0be1f53c211c80a27ffee9a" + "zendframework/zendframework": "dev-master#6bf5dfff1160e6266d8924ab6fefb678ac56f44d" }, "autoload": { "psr-0": { diff --git a/module/Application/Module.php b/module/Application/Module.php index 0ed2ef2..a31d253 100644 --- a/module/Application/Module.php +++ b/module/Application/Module.php @@ -8,4 +8,15 @@ class Module { return include __DIR__ . '/config/module.config.php'; } + + public function getAutoloaderConfig() + { + return array( + 'Zend\Loader\StandardAutoloader' => array( + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, + ), + ), + ); + } } diff --git a/public/index.php b/public/index.php index 6685f6f..5d7a3d7 100644 --- a/public/index.php +++ b/public/index.php @@ -5,15 +5,23 @@ use Zend\Mvc\Service\ServiceManagerConfiguration; chdir(dirname(__DIR__)); -// Allow using an alternative copy of ZF2 -if (getenv('ZF2_PATH')) { - require_once getenv('ZF2_PATH') . '/Zend/Loader/AutoloaderFactory.php'; - AutoloaderFactory::factory(); +// Composer autoloading +if (file_exists('vendor/autoload.php')) { + $loader = include 'vendor/autoload.php'; } -// Composer autoloading -if (!include_once('vendor/autoload.php')) { - throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?'); +// Support for ZF2_PATH environment variable or git submodule +if ($zf2Path = getenv('ZF2_PATH') ?: (is_dir('vendor/ZF2/library') ? 'vendor/ZF2/library' : false)) { + if (isset($loader)) { + $loader->add('Zend', $zf2Path . '/Zend'); + } else { + include $zf2Path . '/Zend/Loader/AutoloaderFactory.php'; + AutoloaderFactory::factory(); + } +} + +if (!class_exists('Zend\Loader\AutoloaderFactory')) { + throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.'); } // Get application stack configuration diff --git a/vendor/ZF2 b/vendor/ZF2 new file mode 160000 index 0000000..6bf5dff --- /dev/null +++ b/vendor/ZF2 @@ -0,0 +1 @@ +Subproject commit 6bf5dfff1160e6266d8924ab6fefb678ac56f44d -- 1.7.10.4