Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Bootstrap #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 33 additions & 23 deletions test/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class Bootstrap
{
protected static $serviceManager;
protected static $config;
protected static $bootstrap;

public static function init()
{
Expand All @@ -23,12 +25,15 @@ public static function init()
$testConfig = include __DIR__ . '/TestConfig.php.dist';
}

$zf2ModulePaths = array(dirname(dirname(__DIR__)));
if (($path = static::findParentPath('vendor'))) {
$zf2ModulePaths[] = $path;
}
if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) {
$zf2ModulePaths[] = $path;
$zf2ModulePaths = array();

if(isset($testConfig['module_listener_options']['module_paths'])) {
$modulePaths = $testConfig['module_listener_options']['module_paths'];
foreach($modulePaths as $modulePath) {
if (($path = static::findParentPath($modulePath)) ) {
$zf2ModulePaths[] = $path;
}
}
}

$zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
Expand All @@ -48,41 +53,46 @@ public static function init()
$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();

static::$serviceManager = $serviceManager;
static::$config = $config;
}

public static function getServiceManager()
{
return static::$serviceManager;
}

public static function getConfig()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hounddog

What's this method needed for?

{
return static::$config;
}

protected static function initAutoloader()
{
$vendorPath = static::findParentPath('vendor');

if (is_readable($vendorPath . '/autoload.php')) {
$loader = include $vendorPath . '/autoload.php';
}
} else {
$zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));

if (!$zf2Path) {
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
}

$zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';

if (!$zf2Path) {
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
}

if (isset($loader)) {
$loader->add('Zend', $zf2Path . '/Zend');
} else {
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
),
AutoloaderFactory::factory(array(
'Zend\Loader\StandardAutoloader' => array(
'autoregister_zf' => true,
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__,
),
));
}
),
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hounddog

I believe this whole autoloading thing should left to Composer.

}

protected static function findParentPath($path)
Expand All @@ -98,4 +108,4 @@ protected static function findParentPath($path)
}
}

Bootstrap::init();
Bootstrap::init();
8 changes: 6 additions & 2 deletions test/TestConfig.php.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php
define('ZF2_PATH', getenv('HOME') . '/workspace/zf2/library');

return array(
'modules' => array(
'ZfcBase',
),
'module_listener_options' => array(
'module_paths' => array(
'module',
'vendor',
),
),
);