Update index.php and Application\Module to make composer use optional
authorEvan Coury <me@evancoury.com>
Wed, 13 Jun 2012 22:42:12 +0000 (15:42 -0700)
committerEvan Coury <me@evancoury.com>
Wed, 13 Jun 2012 23:06:00 +0000 (16:06 -0700)
- 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
README.md
composer.json
module/Application/Module.php
public/index.php
vendor/ZF2 [new submodule]

index 8f630ff..040b52e 100644 (file)
@@ -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
index dd9072b..4e7d164 100644 (file)
--- 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
index 1d6bc58..86591c3 100644 (file)
@@ -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": {
index 0ed2ef2..a31d253 100644 (file)
@@ -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__,
+                ),
+            ),
+        );
+    }
 }
index 6685f6f..5d7a3d7 100644 (file)
@@ -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 (submodule)
index 0000000..6bf5dff
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 6bf5dfff1160e6266d8924ab6fefb678ac56f44d