// ------ 决定“服务管理器”配置的位置 ------
// 1、在模块的入口类/data/www/www.domain.com/www/module/Module1/Module.php中实现了“服务管理器声明”的注入的接口,那么会进行调用 注入
$albumModule->getMyMailManagerConfig(); // 2、在如下路径获取的到配置中配置了“服务管理器声明”的键: $configListener->getMergedConfig(false)['my_mails']
2.0 可在模块的入口类/data/www/www.domain.com/www/module/Module1/Module.php中$modulex->getConfig()配置的$modulex->getConfig();
2.1 $applicationConfig['module_listener_options']['ConfigGlobPaths']抓取的内容
2.2 $applicationConfig['module_listener_options']['ConfigStaticPaths']抓取的内容
2.3 $applicationConfig['module_listener_options']['ExtraConfig']配置的内容 // ------ ServiceManagers 服务管理器是如何创建实例的------
1、查询"对等的服务管理器"中是否存在指定实例对象
2、依次尝试使用如下的方式创建对象
isset($this->aliases[$cName])
isset($this->delegators[$cName])
isset($this->factories[$cName])
isset($this->invokableClasses[$cName])
$this->abstractFactories->canCreateServiceWithName($this, $cName, $rName) $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()配置的
        ) // ------ 如何创建、使用自己的“服务管理器” ------
1、编写“服务管理器”相关类
// 1.0 声明“服务管理器”配置注入入口
namespace Zendx\MyMailPluginManager\Feature;
interface MyMailPluginManagerProviderInterface {
public function getMyMailPluginManagerConfig();
} //1.1 编写“服务管理器”业务代码
namespace Zendx\MyMailPluginManager\;
class MyMailPluginManager extends AbstractPluginManager
{
public function __construct(ConfigInterface $configuration = null)
{
parent::__construct($configuration);
$this->addInitializer(array($this, 'injectDependencies'), false);
} public function injectDependencies($mailPlugin, ServiceLocatorInterface $serviceLocator)
{
} public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = false)
{
return parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers);
} public function get($name, $options = array(), $usePeeringServiceManagers = false)
{
return parent::get($name, $options, $usePeeringServiceManagers);
}
} 2、使用“服务管理器”
2.1、声明“服务管理器”的创建方式
$applicationConfig = array(
// 服务管理器的配置
'service_manager' => array(
// ...
'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',
),
// ...
)
// ...
);
2.2、声明 配置“服务管理器”的方式
$applicationConfig = array(
// ...
'service_listener_options'=>array(
// ...
'key_non_used_1'=>array( // 扩展自己的管理器 $serviceManager->get('MyMailPluginManager');
'service_manager'=>'MyMailPluginManager',
'config_key'=>'my_mail_plugin_manager', // $configListener->getMergedConfig(false)['my_mails']
// 从模块入口类中获取配置的方式
// 只需 /data/www/www.domain.com/www/module/Module1/Module.php 中的 Module 类实现如下内容
'interface'=>'Zendx\MyMailPluginManager\Feature\MyMailPluginManagerProviderInterface',
'method'=>'getMyMailPluginManagerConfig', // $albumModule->getMyMailPluginManagerConfig();
),
// ...
)
// ...
); 2.3、配置
2.3.0 可在模块的入口类/data/www/www.domain.com/www/module/Module1/Module.php中实现“服务管理器声明”的注入的接口,那么会自动进行调用 注入
namespace Module1;
class Module implements ...,MyMailPluginManagerProviderInterface
{
// ...
public function getMyMailPluginManagerConfig()
{
return include __DIR__ . '/config/my_mail_plugin_manager.config.php';
}
// ...
} 2.3.1.0 可在模块的入口类/data/www/www.domain.com/www/module/Module1/Module.php中$modulex->getConfig()配置
$modulex->getConfig(); // return include __DIR__ . '/config/module.config.php';
2.3.1.1可在 $applicationConfig['module_listener_options']['ConfigGlobPaths']路径中的文件配置
2.3.1.2可在 $applicationConfig['module_listener_options']['ConfigStaticPaths']路径中的文件配置
2.3.1.3可在 $applicationConfig = array(
// ...
'module_listener_options'=>array(
// ...
'ExtraConfig'=>array(
'my_mail_plugin_manager'=>array(
'key1'=>'key1_value',
'key2'=>'key2_value',
),
),
// ...
)
// ...
); 2.4、应用
$serviceManager->get('MyMailPluginManager'); // ---------- 例子、模块配置 ----------------
// /data/www/www.domain.com/www/module/Album/config/module.config.php
$moduleConfig = array(
// 配置导航
'navigation'=>array(
'style1'=>''
),
'di'=>array(
'allowed_controllers'=>array(
'Controller1',
'Controller2',
)
),
'view_manager'=>array( // 模板搜索路径
// Zend\View\Resolver\TemplateMapResolver
'template_map'=>'', // Zend\View\Resolver\TemplatePathStack
'template_path_stack'=>array(
'album' => __DIR__ . '/../view',
'module1' => __DIR__ . '/../view',
),
'default_template_suffix'=>'phtml', // Zend\View\Resolver\PrefixPathStackResolver
'prefix_template_path_stack'=>'',
)
); // ------------例子、 Application 应用的配置--------------
// /data/www/www.domain.com/www/config/application.config.php
$applicationConfig = array(
// 服务管理器的配置
'service_manager' => array(
'allow_override'=>null,
'factories'=>array( // 服务的创建方式:调用工厂创建 return $xxxfactory->createService($serviceLocator);
'EventManager' => 'Zend\Mvc\Service\EventManagerFactory',
'ModuleManager' => 'Zend\Mvc\Service\ModuleManagerFactory',
),
'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'
)
)
),
'module_listener_options'=>array(
'ExtraConfig'=>array(
// 配置导航
'navigation'=>array(
'style1'=>''
)
)
),
'service_listener_options'=>array(
'ControllerLoader'=>array(
'service_manager'=>'ControllerLoader',
'config_key'=>'controllers',
'interface'=>'Zend\ModuleManager\Feature\ControllerProviderInterface',
'method'=>'getControllerConfig',
),
'MyMailManager'=>array( // 声明自己的“服务管理器” $serviceManager->get('MyMailManager');
'service_manager'=>'MyMailManager',
'config_key'=>'my_mails',
'interface'=>'Zendx\ModuleManager\Feature\MyMailManagerProviderInterface',
'method'=>'getMyMailManagerConfig',
)
)
);

ZendFramework-2.4 源代码 - 关于服务管理器的更多相关文章

  1. SuperSocket 服务管理器 (ServerManager)

    什么 SuperSocket 服务管理器? SuperSocket 服务管理器是一个让你能够在客户中用图形化界面来管理和监控你的SuperSocket服务器程序的组件. 在服务器端配置服务器管理器 事 ...

  2. windows 服务管理器使用系统内置帐户时密码的输入

    windows 服务管理器使用系统内置帐户时在选择帐户如network services后不需要输入密码,直接确认即可,系统会自动附加密码.

  3. Systemd 服务管理器

    博文链接:http://www.cnblogs.com/zhenghongxin/p/8672199.html 项目中遇到有些脚本需要通过后台进程运行,保证不被异常中断,变成守护进程的第一步,就是把它 ...

  4. 成功安装mysql(mysql-5.5.32-winx64.msi)后,为何服务管理器里找不到MYSQL服务名?

    解决方案: 1.打开cmd,切换到mysql的bin目录下 2. D:\Program Files\MySQL5.1\bin>mysqld.exe -install 成功后会出现:Service ...

  5. Android的Context Manager(服务管理器)源码剖析-android学习之旅(99)

    Context Manager介绍 Context Manager对应的进程是servicemanager进程,它先于Service Server和服务客户端运行,进入接收IPC数据的待机状态,处理来 ...

  6. 成功安装mysql后,为何服务管理器里找不到MYSQL服务名【转】

    解决方案:(参考以下命令) 1.打开cmd,切换到mysql的bin目录下 2. D:\Program Files\MySQL5.1\bin>mysqld.exe -install Servic ...

  7. MySql安装后在服务管理器里边找不到MySql服务项的解决办法(win10)

    问题描述: 成功安装MySql后,使用mysql的时候,在CMD中输入net start mysql,提示服务名无效,查看服务列表也找不到mysql服务. 解决办法: 首先用管理员身份打开CMD命令, ...

  8. 成功安装mysql后,为何服务管理器里找不到MYSQL服务名

    1.打开cmd,切换到mysql的bin目录下 2. D:\Program Files\MySQL5.1\bin>mysqld.exe -installService successfully ...

  9. 用Java开发一个本地服务管理软件

    一.最终界面先贴上最终效果图,图1为初始化界面,图二为点击启动/停止之后的中间过渡状态,图三为启动成功后弹出的提示框 把动态gif图片嵌入到jpg背景图中?用Adobe ImageReady即可办到 ...

随机推荐

  1. eclipse自动添加版权信息

    Preference->Java->Code Style->Code Template->comments->Files->Edit 勾选上Automaticall ...

  2. C/C++规范学习:

    一 关于浮点数: 1.1浮点数是否等于0判断:因为浮点数都有精度,不能拿浮点数直接和0.0f进行比较,而应该采用以下方法: if (f32Data == 0.0f) // 隐含错误的比较 #defin ...

  3. Spring Boot 测试 junit

    import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.ann ...

  4. Python lambda(匿名函数)介绍【转】

    引用: http://www.cnblogs.com/evening/archive/2012/03/29/2423554.html 在学习python的过程中,lambda的语法时常会使人感到困惑, ...

  5. vscode 插件todo-highlight

    简介 Highlight TODO,FIXME or any annotations within your code. 资源 https://marketplace.visualstudio.com ...

  6. RabbitMQ 消息的可靠投递

    mq 提供了两种方式确认消息的可靠投递 confirmCallback 确认模式 returnCallback 未投递到 queue 退回模式 在使用 RabbitMQ 的时候,作为消息发送方希望杜绝 ...

  7. linux启动mysql报错 Starting MySQL... ERROR! The server quit without updating PID file (XXXX pid文件位置)

    最近在云服务器上安装mysql  启动时报错了,从错误中可以看出,定位在pid文件上,有三种解决方案 1.重启服务器:因为服务器更新时,可能会禁用某些守护进程,重启后即可恢复 2.删除配置文件,重启试 ...

  8. 如何避开JavaScript浮点数计算精度问题(如0.1+0.2!==0.3)

    不知道大家在使用JS的过程中有没有发现某些浮点数运算的时候,得到的结果存在精度问题:比如0.1 + 0.2 = 0.30000000000000004以及7 * 0.8 = 5.60000000000 ...

  9. zabbix-3.4-服务监控

    服务监控 总览 服务监控(services monitoring)旨在帮助那些想要高级(业务)基础设施的监控的人.在许多情况下,我们关注的不是底层细节,比如磁盘空间不足.CPU 负载高等.我们关注的是 ...

  10. 永洪BI——国内领军的一站式大数据分析平台

    平台: CentOS 类型: 虚拟机镜像 软件包: jdk-7.79-linux yonghongbi.sh basic software big data business intelligence ...