// ------ 决定“服务管理器”配置的位置 ------
// 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. HDU 6153 A Secret 套路,求解前缀在本串中出现的次数

    http://acm.hdu.edu.cn/showproblem.php?pid=6153 首先相当于翻转两个串,然后求s2前缀在s1中出现的次数. 这是一个套路啦 首先把两个串结合起来,中间加一个 ...

  2. 360或其他双核浏览器下在兼容模式用chrome内核渲染的方法

    <meta name="renderer" content="webkit"> <meta http-equiv="X-UA-COM ...

  3. C# 多线程之线程控制

    方案一: 调用线程控制方法.启动:Thread.Start();停止:Thread.Abort();暂停:Thread.Suspend();继续:Thread.Resume(); private vo ...

  4. Linux下安装软件遇见的问题汇总

    1.安装monodevelop 安装环境Linux Mint17.1 在软件在中心直接安装monodevelop,安装完成后直接启动界面“一闪而过”,解决办法: 软件中心安装 mono-complet ...

  5. IDEA运行时报错(IDEA不识别新语法):Error:java: Compilation failed: internal java compiler error

    File-->setting...-->Buil,Execution,Deployment-->Compiler-->Java Compiler中,改一下Module,我的原来 ...

  6. 会话跟踪之Session

    Session是服务端使用记录客户端状态的一种机制,Session使用简单,但是和Cookie相比,增加了服务器的存储压力[因为为了追求速度,服务器将Session放置在了内存中].Cookie是保存 ...

  7. Android 关于Acitivity 的setFlag以及launchmode的总结

    Intent几种常见的flags: .FLAG_ACTIVITY_NEW_TASK:当Intent对象包含这个标记时,系统会寻找或创建一个新的task来放置目标Activity,寻找时依据目标Acti ...

  8. mysql decimal类型与decimal长度用法详解

    三者的区别介绍 float:浮点型,含字节数为4,32bit,数值范围为-3.4E38~3.4E38(7个有效位) double:双精度实型,含字节数为8,64bit数值范围-1.7E308~1.7E ...

  9. Spring MVC的高级配置

    1.文件上传配置 文件上传是项目中常用的一个功能,Spring MVC通过配置一个MultipartResolver来上传文件. 在Spring的控制器中,通过MultipartFile file 来 ...

  10. IBM WebSphere MQ安装及配置详解

    打开MQ安装程序,选择下一步,默认安装WebSphere MQ, 完成MQ的安装工作,启动WebSphere MQ, 服务器配置,选择新建队列管理器,创建名为 "mq"的队列管理器 ...