1 // Composer autoloading
2 if (file_exists('vendor/autoload.php')) {
// 加载自动加载器
3 $loader = include 'vendor/autoload.php';
4 }
5
6 if (class_exists('Zend\Loader\AutoloaderFactory')) {
// 如果已经加载过了直接返回
7 return;
8 }
9
10 $zf2Path = false;
11
12 if (is_dir('vendor/ZF2/library')) {
// 默认的框架路径
13 $zf2Path = 'vendor/ZF2/library';
14 } elseif (getenv('ZF2_PATH')) { // Support for ZF2_PATH environment variable or git submodule
// 根据环境配置获取框架路径(大写)
15 $zf2Path = getenv('ZF2_PATH');
16 } elseif (get_cfg_var('zf2_path')) { // Support for zf2_path directive value
// 根据环境配置获取框架路径(小写)
17 $zf2Path = get_cfg_var('zf2_path');
18 }
19
20 if ($zf2Path) {
21 if (isset($loader)) {
// 在定义了自动加载器的情况下自动加载
22 $loader->add('Zend', $zf2Path);
23 $loader->add('ZendXml', $zf2Path);
24 } else {
// 引入加载器
25 include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
26 Zend\Loader\AutoloaderFactory::factory(array(
27 'Zend\Loader\StandardAutoloader' => array(
28 'autoregister_zf' => true
29 )
30 ));
31 }
32 }
33
34 if (!class_exists('Zend\Loader\AutoloaderFactory')) {
// 加载器加载失败抛出异常
35 throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
36 }