首页 > 代码库 > ZendFramework-2.4 源代码 - 关于配置

ZendFramework-2.4 源代码 - 关于配置

 

$applicationConfig = $serviceManager->setService(‘ApplicationConfig‘); // 获取配置  /data/www/www.domain.com/www/config/application.config.php
    
    // -----------case.0------------------
    // -----------服务管理器的配置------------------
    $applicationConfig = array(
        // ...
        ‘service_manager‘=>array(
            ‘allow_override‘=>null,
            ‘factories‘=>array( // 服务的创建方式:调用工厂创建  return $xxxfactory->createService($serviceLocator);
                ‘EventManager‘  => ‘Zend\Mvc\Service\EventManagerFactory‘,
                ‘ModuleManager‘ => ‘Zend\Mvc\Service\ModuleManagerFactory‘,
                // ‘LazyServiceFactory‘ => ‘Zend\ServiceManager\Proxy\LazyServiceFactoryFactory‘,
            ),
            ‘abstract_factories‘=>array( // 服务的创建方式:调用抽象工厂创建 $abstractFactory->createServiceWithName($serviceLocator,$cName, $rName); 
                // 服务的获取方式:$serviceManager->get(‘zendnavigationstyle1‘);
                ‘zendnavigationstyle1‘=>‘Zend\Navigation\Service\NavigationAbstractServiceFactory‘
            ),
            ‘invokables‘ => array( // 服务的创建方式:直接 new 出对象  return new $invokable();
                ‘SharedEventManager‘ => ‘Zend\EventManager\SharedEventManager‘,
                ‘Album\Service\AlbumServiceInterface‘ => ‘Album\Service\AlbumService‘,// return (new Album\Service\AlbumService());
                ‘Zendx\ModuleManager\Feature\MyMailManagerProviderInterface‘ => ‘Zendx\ModuleManager\Feature\MyMailManagerProvider‘,
            ),
            ‘services‘=>array( // 服务的创建方式:“键值对”的“值”是实例对象
                ‘instance_1‘=>new Instance_1(),
                ‘PHPMailer‘=>new PHPMailer(), // $serviceManager->get(‘PHPMailer‘);
                ‘myconfig1‘=>array( // $serviceManager->get(‘myconfig1‘);
                    ‘key1‘=>‘key1_value‘,
                    ‘key2‘=>‘key2_value‘,
                ),    
            ),
            ‘aliases‘=>array( // 别名  
                // 服务的获取方式:$serviceManager->get(‘Zend\EventManager\EventManagerInterface‘) === $serviceManager->get(‘EventManager‘);
                ‘Zend\EventManager\EventManagerInterface‘     => ‘EventManager‘,
                ‘Zend\ServiceManager\ServiceLocatorInterface‘ => ‘ServiceManager‘,
                ‘Zend\ServiceManager\ServiceManager‘          => ‘ServiceManager‘,
            ),
            ‘initializers‘=>array( // 创建完对象的初始化器
                ‘ServiceLocatorAwareInitializer‘ => function ($instance, ServiceLocatorInterface $serviceLocator) {
                    if ($instance instanceof ServiceLocatorAwareInterface) {
                        $instance->setServiceLocator($serviceLocator);
                    }
                }
            ),
            ‘shared‘=>array( // 创建出来的对象是否共享。如果不配置,默认是共享的。
                ‘EventManager‘ => false, 
            ),
            ‘delegators‘=>array(  // 委托
                ‘lazyService‘=>array(
                    ‘LazyServiceFactory‘
                )
            )
        ),
        // ...
    )
    $applicationConfig[‘service_manager‘] ---影响--->  Zend\ServiceManager\ServiceManager(new Service\ServiceManagerConfig($applicationConfig[‘service_manager‘]));
    
    // -----------模块监听器的配置------------------
    $applicationConfig = array(
        // ...
        ‘module_listener_options‘=>array(
            // Zend\ModuleManager\Listener\ConfigListener的配置
            ‘ConfigCacheEnabled‘=>false, // 配置缓存是否启用
            ‘ConfigCacheFile‘=>__DIR__.‘/cache/mergedConfigCacheFile.config.php‘, // 配置缓存文件的名字,即:所有配置文件合并后的文件名 /data/www/www.domain.com/www/config/mergedConfigCacheFile.cache.php
            ‘ConfigGlobPaths‘=>array( // 配置文件抓取的路径
                ‘config/autoload/{,*.}{global,local}.php‘,
            ), 
            ‘ConfigStaticPaths‘=>array(), // 配置文件的静态的路径
            
            // Zend\Loader\ModuleAutoloader的配置
            ‘ModulePaths‘=>array(
                // 完整匹配
                ‘Zendx\Payment‘=>__DIR__.‘/../library/Zendx/Payment‘, // new Zendx\Payment\Module() ---> /data/www/www.domain.com/www/library/Zendx/Payment/Module.php
                ‘Zendx\PHPExcel‘=>__DIR__.‘/../library/Zendx/PHPExcel‘, // new Zendx\PHPExcel\Module() ---> /data/www/www.domain.com/www/library/Zendx/PHPExcel/Module.php
                // 前缀匹配
                ‘Zendx\Wechat\*‘=>__DIR__.‘/../library/Zendx/Wechat‘, // new Zendx\Wechat\PublicPlatform\Module() OR new Zendx\Wechat\Security\Module() ---> /data/www/www.domain.com/www/library/Security/Module.php
                // 自动搜索
                ‘./module‘, // new Module1\Module(); ---> ./module/Module1/Module.php  OR new Module1\Module1Sub\Module(); ---> ./module/Module1/Module1Sub/Module.php
                ‘./vendor‘,
            ),
            ‘ModuleMapCacheEnabled‘=>false, // 模块加载路径的缓存是启用
            ‘ModuleMapCacheFile‘=>__DIR__.‘/cache/moduleMapCacheFile.config.php‘,
            
            // 在ConfigListener做配置文件合并时会放入
            ‘ExtraConfig‘=>array(
            
            )
        )
        // ...
    );
    $applicationConfig[‘module_listener_options‘] ---影响--->  Zend\ModuleManager\Listener\DefaultListenerAggregate(new ListenerOptions($moduleListenerOptions)) 内的监听器
    $moduleListenerOptions = $applicationConfig[‘module_listener_options‘];
    $moduleListenerOptions[‘ConfigGlobPaths‘]/$moduleListenerOptions[‘ConfigStaticPaths‘]  ---影响--->  new Zend\ModuleManager\Listener\ConfigListener($moduleListenerOptions)
    没有配置项  ---影响--->  Zend\ModuleManager\Listener\LocatorRegistrationListener($moduleListenerOptions)
    $moduleListenerOptions[‘ModuleMapCacheEnabled‘]/$moduleListenerOptions[‘ModulePaths‘]/$moduleListenerOptions[‘ModuleMapCacheFile‘]  ---影响--->  Zend\ModuleManager\Listener\ModuleLoaderListener($moduleListenerOptions)
    没有配置项  ---影响--->  Zend\ModuleManager\Listener\AutoloaderListener($moduleListenerOptions)
    没有配置项  ---影响--->  Zend\ModuleManager\Listener\InitTrigger($moduleListenerOptions)
    没有配置项  ---影响--->  Zend\ModuleManager\Listener\OnBootstrapListener($moduleListenerOptions)

    // -----------服务管理器配置注入的声明------------------
    
    $applicationConfig = array(
        // ...
        ‘service_listener_options‘=>array(
            ‘key_non_used_1‘=>array( // 扩展自己的管理器 $serviceManager->get(‘MyMailManager‘);
                ‘service_manager‘=>‘MyMailManager‘,
                ‘config_key‘=>‘my_mails‘, // $configListener->getMergedConfig(false)[‘my_mails‘]
                // 从模块入口类中获取配置的方式
                // 只需 /data/www/www.domain.com/www/module/Module1/Module.php 中的 Module 类实现如下内容
                ‘interface‘=>‘Zendx\ModuleManager\Feature\MyMailManagerProviderInterface‘,
                ‘method‘=>‘getMyMailManagerConfig‘, // $albumModule->getMyMailManagerConfig();
            ),
            ‘key_non_used_2‘array(
                ‘service_manager‘=>‘LogWriterManager‘,
                ‘config_key‘=>‘log_writers‘,
                ‘interface‘=>‘Zend\ModuleManager\Feature\LogWriterProviderInterface‘,
                ‘method‘=>‘getLogWriterConfig‘
            )
        )
        // ...
    );
    $serviceListenerOptions = $applicationConfig[‘service_listener_options‘];
    $applicationConfig[‘service_listener_options‘]  ---影响--->  Zend\ModuleManager\Listener\ServiceListener($serviceLocator, $this->defaultServiceConfig)
    
    // -----------模块管理器的配置------------------ 
    // 模块管理器,负责统一管理各个模块
    $applicationConfig = array(
        // ...
        ‘modules‘ => array(
            ‘Application‘,
            ‘Album‘,
            ‘Module1‘,
            ‘Module1\Module1Sub‘, // ---> /data/www/www.domain.com/www/module/Module1/Module1Sub/Module.php
            ‘Module1\Module1Sub\Module1SubSub‘, // ---> /data/www/www.domain.com/www/module/Module1/Module1Sub/Module1SubSub/Module.php
        )
        // ...
    );
    $applicationConfig[‘modules‘] ---影响---> new Zend\ModuleManager\ModuleManager($application[‘modules‘], $events);
    
    // -----------case.1------------------
    // -----------应用监听器的配置------------------
    $serviceManager->get(‘Config‘) =  $configListener->getMergedConfig(false) 
        === array_merge(
                根据$applicationConfig[‘module_listener_options‘][‘ConfigGlobPaths‘]抓取的,
                根据$applicationConfig[‘module_listener_options‘][‘ConfigStaticPaths‘]抓取的,
                根据$applicationConfig[‘module_listener_options‘][‘ExtraConfig‘]配置的,
                $modulex->getConfig()配置的
        )
    
    $applicationConfig = array(
        // ...
        ‘listeners‘ => array(
            ‘RouteListener‘,
            ‘DispatchListener‘,
            ‘HttpMethodListener‘,
            ‘ViewManager‘,
            ‘SendResponseListener‘,
        )
        // ...
    );
    $listeners = array_merge($config[‘listeners‘], $applicationConfig[‘listeners‘])
    $listeners ---影响--->  Zend\Mvc\Application::bootstrap($applicationConfig[‘listeners‘]) 

 

ZendFramework-2.4 源代码 - 关于配置