@@ 16-96 (lines=81) @@ | ||
13 | /** |
|
14 | * Test bootstrap, for setting up autoloading |
|
15 | */ |
|
16 | class Bootstrap |
|
17 | { |
|
18 | protected static $serviceManager; |
|
19 | ||
20 | public static function init() |
|
21 | { |
|
22 | $zf2ModulePaths = array(dirname(dirname(__DIR__))); |
|
23 | if (($path = static::findParentPath('vendor'))) { |
|
24 | $zf2ModulePaths[] = $path; |
|
25 | } |
|
26 | if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) { |
|
27 | $zf2ModulePaths[] = $path; |
|
28 | } |
|
29 | ||
30 | static::initAutoloader(); |
|
31 | ||
32 | // use ModuleManager to load this module and it's dependencies |
|
33 | $config = array( |
|
34 | 'module_listener_options' => array( |
|
35 | 'module_paths' => $zf2ModulePaths, |
|
36 | ), |
|
37 | 'modules' => array( |
|
38 | 'Application' |
|
39 | ) |
|
40 | ); |
|
41 | ||
42 | $serviceManager = new ServiceManager(new ServiceManagerConfig()); |
|
43 | $serviceManager->setService('ApplicationConfig', $config); |
|
44 | $serviceManager->get('ModuleManager')->loadModules(); |
|
45 | static::$serviceManager = $serviceManager; |
|
46 | } |
|
47 | ||
48 | public static function chroot() |
|
49 | { |
|
50 | $rootPath = dirname(static::findParentPath('module')); |
|
51 | chdir($rootPath); |
|
52 | } |
|
53 | ||
54 | public static function getServiceManager() |
|
55 | { |
|
56 | return static::$serviceManager; |
|
57 | } |
|
58 | ||
59 | protected static function initAutoloader() |
|
60 | { |
|
61 | $vendorPath = static::findParentPath('vendor'); |
|
62 | ||
63 | if (file_exists($vendorPath.'/autoload.php')) { |
|
64 | include $vendorPath.'/autoload.php'; |
|
65 | } |
|
66 | ||
67 | if (! class_exists('Zend\Loader\AutoloaderFactory')) { |
|
68 | throw new RuntimeException( |
|
69 | 'Unable to load ZF2. Run `php composer.phar install`' |
|
70 | ); |
|
71 | } |
|
72 | ||
73 | AutoloaderFactory::factory(array( |
|
74 | 'Zend\Loader\StandardAutoloader' => array( |
|
75 | 'autoregister_zf' => true, |
|
76 | 'namespaces' => array( |
|
77 | __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__, |
|
78 | ), |
|
79 | ), |
|
80 | )); |
|
81 | } |
|
82 | ||
83 | protected static function findParentPath($path) |
|
84 | { |
|
85 | $dir = __DIR__; |
|
86 | $previousDir = '.'; |
|
87 | while (!is_dir($dir . '/' . $path)) { |
|
88 | $dir = dirname($dir); |
|
89 | if ($previousDir === $dir) { |
|
90 | return false; |
|
91 | } |
|
92 | $previousDir = $dir; |
|
93 | } |
|
94 | return $dir . '/' . $path; |
|
95 | } |
|
96 | } |
|
97 | ||
98 | Bootstrap::init(); |
|
99 | Bootstrap::chroot(); |
@@ 16-96 (lines=81) @@ | ||
13 | /** |
|
14 | * Test bootstrap, for setting up autoloading |
|
15 | */ |
|
16 | class Bootstrap |
|
17 | { |
|
18 | protected static $serviceManager; |
|
19 | ||
20 | public static function init() |
|
21 | { |
|
22 | $zf2ModulePaths = array(dirname(dirname(__DIR__))); |
|
23 | if (($path = static::findParentPath('vendor'))) { |
|
24 | $zf2ModulePaths[] = $path; |
|
25 | } |
|
26 | if (($path = static::findParentPath('module')) !== $zf2ModulePaths[0]) { |
|
27 | $zf2ModulePaths[] = $path; |
|
28 | } |
|
29 | ||
30 | static::initAutoloader(); |
|
31 | ||
32 | // use ModuleManager to load this module and it's dependencies |
|
33 | $config = array( |
|
34 | 'module_listener_options' => array( |
|
35 | 'module_paths' => $zf2ModulePaths, |
|
36 | ), |
|
37 | 'modules' => array( |
|
38 | 'Application' |
|
39 | ) |
|
40 | ); |
|
41 | ||
42 | $serviceManager = new ServiceManager(new ServiceManagerConfig()); |
|
43 | $serviceManager->setService('ApplicationConfig', $config); |
|
44 | $serviceManager->get('ModuleManager')->loadModules(); |
|
45 | static::$serviceManager = $serviceManager; |
|
46 | } |
|
47 | ||
48 | public static function chroot() |
|
49 | { |
|
50 | $rootPath = dirname(static::findParentPath('module')); |
|
51 | chdir($rootPath); |
|
52 | } |
|
53 | ||
54 | public static function getServiceManager() |
|
55 | { |
|
56 | return static::$serviceManager; |
|
57 | } |
|
58 | ||
59 | protected static function initAutoloader() |
|
60 | { |
|
61 | $vendorPath = static::findParentPath('vendor'); |
|
62 | ||
63 | if (file_exists($vendorPath.'/autoload.php')) { |
|
64 | include $vendorPath.'/autoload.php'; |
|
65 | } |
|
66 | ||
67 | if (! class_exists('Zend\Loader\AutoloaderFactory')) { |
|
68 | throw new RuntimeException( |
|
69 | 'Unable to load ZF2. Run `php composer.phar install`' |
|
70 | ); |
|
71 | } |
|
72 | ||
73 | AutoloaderFactory::factory(array( |
|
74 | 'Zend\Loader\StandardAutoloader' => array( |
|
75 | 'autoregister_zf' => true, |
|
76 | 'namespaces' => array( |
|
77 | __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__, |
|
78 | ), |
|
79 | ), |
|
80 | )); |
|
81 | } |
|
82 | ||
83 | protected static function findParentPath($path) |
|
84 | { |
|
85 | $dir = __DIR__; |
|
86 | $previousDir = '.'; |
|
87 | while (!is_dir($dir . '/' . $path)) { |
|
88 | $dir = dirname($dir); |
|
89 | if ($previousDir === $dir) { |
|
90 | return false; |
|
91 | } |
|
92 | $previousDir = $dir; |
|
93 | } |
|
94 | return $dir . '/' . $path; |
|
95 | } |
|
96 | } |
|
97 | ||
98 | Bootstrap::init(); |
|
99 | Bootstrap::chroot(); |