// ------ 决定“服务管理器”配置的位置 ------
// 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. 019 Remove Nth Node From End of List 删除链表的倒数第N个节点

    给定一个链表,删除链表的倒数第 n 个节点并返回头结点.例如,给定一个链表: 1->2->3->4->5, 并且 n = 2.当删除了倒数第二个节点后链表变成了 1->2 ...

  2. Lecture--9 Sorting

    1/排序算法:冒泡排序bubble sort,插入排序 insertion sort,选择排序 selection sort,快速排序 quick sort,归并排序 merge sort;堆排序 h ...

  3. Java文件与io——装饰者模式

    意图: 动态地给一个对象添加一些额外的职责.就增加功能来说,Decorator模式相比于生成子类更为灵活.该模式以对客户端透明的方式扩展对象的功能. 适用环境 在不影响其他对象的情况下,以动态.透明的 ...

  4. c/s和b/s的区别及实例说明【转】

    B/S结构,即Browser/Server(浏览器/服务器)结构,是随着Internet技术的兴起,对C/S结构的一种变化或者改进的结构.在这种结构下,用户界面完全通过WWW浏览器实现,一部分事务逻辑 ...

  5. ASP.NET MVC缓存

    根据缓存的位置不同,可以区分为: ①客户端缓存(缓存在用户的客户端,例如浏览器中) ②服务器缓存(缓存在服务器中,可以缓存在内存中,也可以缓存在文件里,并且还可以进一步地区分为本地缓存和分布式缓存两种 ...

  6. 完美解决Android在listview添加checkbox实现单选多选操作问题

    在Android某些开发需求当中,有时候需要在listveiw中加入checkbox实现单选,多选操作.表面上看上去只是改变checkbox那么简单,然而实际开发中,实现起来并不是那么得心应手.尤其当 ...

  7. OS进程同步与通信

    信号量机制 信号量用于互斥 P(S) 临界区 V(S) ----- P(S) 临界区 V(S) 生产者消费者: typedef int semaphore //信号量值设置为1就是互斥量 semaph ...

  8. linux 修改myql 编码配置等信息参考

    mysql 配置: 1:编辑配置文件: vi /etc/my.cnf 2:修改配置如下: [client] password        = 123456 port            = 330 ...

  9. Android在应用设置里关闭权限,返回生命周期处理

    问题 在处理6.0运行时权限时,很多人都忽略了这样一个问题: 在一个App应用里,如果已经允许了一个权限比如(读取通讯权限),此刻去调用相机,弹出权限申请对话框,此刻点击拒绝,然后经过处理后弹出去设置 ...

  10. Eucalyptus常用查询命令

    前言: Elastic Utility Computing Architecture for Linking Your Programs To Useful Systems (Eucalyptus)  ...