// ------ 决定“服务管理器”配置的位置 ------
// 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. GCD Guessing Game Gym - 100085G 猜数字 gcd

    http://codeforces.com/gym/100085/attachments 因为那个数字是一个质数,这样的猜的次数是最多的,所以至少是质数次. 但是如果需要猜2.3,那么可以直接猜6,也 ...

  2. 10 - EmbeddedChannel-测试ChannelHandler链

    方法 职责 writeInbound(Object... msgs) 将入站消息写入到EmbeddedChannel中 readInbound() 从EmbeddedChannel中读取一个入站消息, ...

  3. Kotlin容器

    1. 容器 可变/不可变 List<out T> 只读list; MutableList<T>; Set<out T>/MutableSet<T> Ma ...

  4. <Linux系统minfo命令用法>

    minfo命令——ms-dos文件系统的各项参数的显示 minfo这个指令主要用于显示MS-DOS文件系统的各项参数,包括扇区数.磁头数.柱面数等. 参数主要有以下几个: -v 显示详细的参数 dri ...

  5. X64下IIS调用32位的dll

    WebAPI项目中遇到了需要调用32位C++的dll的情况,调试的时候能正常调用,但是发布了之后部署在IIS中出现了BadFormatImage异常, 解决方法是在IIS中相应应用程序池=>高级 ...

  6. 内容显示分页数字分页 aspx

    此处是aspx里面分页显示,数据层和业务层是由动软生成 当然,我们也可以可以利用listView实现分页ListView(高效分页) public partial class NewList : Sy ...

  7. ubuntu配置硬盘开机自动挂载

    1.创建/media/fly文件夹 sudo mkdir /home/fly    #根据个人喜好命名 2.获取要自动挂载的分区的UUID和分区类型TYPE sudo blkid 出现如下结果:   ...

  8. 实现简单Restful API

    1. 首选我们通过 http://start.spring.io/ 网址生成一个基础spring boot 项目,截图配置如下: 点击 generate Project 按钮生成并下载基础项目 2. ...

  9. [翻译] Facebook HHVM 团队封闭开发三周成果展

    本人翻译的一篇文章,首发于伯乐在线. [补充信息]HipHop for PHP是一系列PHP脚本语言的程式码转换器的集合,它包含HPHPc.HPHPi.HPHPd以及HHVM,这四个脚本引擎各有所不同 ...

  10. yum 安装Tomcat7(centos)

    yum 安装Tomcat7   其实最重要的就是yum源吗.初始源的里面既没有nginx也没有tomcat7. 1,搞定nginx,她家自己有源的: rpm -ivh http://nginx.org ...