Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Commit

Permalink
Update index.php and Application\Module to make composer use optional
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
EvanDotPro committed Jun 13, 2012
1 parent d5f0f32 commit 7ac195f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .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
29 changes: 1 addition & 28 deletions README.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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": {
Expand Down
11 changes: 11 additions & 0 deletions module/Application/Module.php
Expand Up @@ -8,4 +8,15 @@ public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
22 changes: 15 additions & 7 deletions public/index.php
Expand Up @@ -5,15 +5,23 @@

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
Expand Down
1 change: 1 addition & 0 deletions vendor/ZF2
Submodule ZF2 added at 6bf5df

0 comments on commit 7ac195f

Please sign in to comment.