本文整理汇总了PHP中Zend\ServiceManager\ServiceLocatorInterface::setFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceLocatorInterface::setFactory方法的具体用法?PHP ServiceLocatorInterface::setFactory怎么用?PHP ServiceLocatorInterface::setFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceLocatorInterface
的用法示例。
在下文中一共展示了ServiceLocatorInterface::setFactory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createService
/**
* Creates and returns the module manager
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ServiceLocatorInterface $serviceLocator
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'HumusMvc\\Service\\ServiceListenerFactory');
}
if (!$serviceLocator->has('Zf1MvcListener')) {
$serviceLocator->setFactory('Zf1MvcListener', 'HumusMvc\\Service\\Zf1MvcListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig');
$serviceListener->addServiceManager('ActionHelperManager', 'action_helpers', 'HumusMvc\\ModuleManager\\Feature\\ActionHelperProviderInterface', 'getActionHelperConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$sharedEvents = $events->getSharedManager();
$sharedEvents->attach('HumusMvc\\Application', 'bootstrap', new LocaleListener());
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例2: createService
/**
* Creates and returns the module manager
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ServiceLocatorInterface $serviceLocator
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ControllerLoader', 'controllers', 'Zend\\ModuleManager\\Feature\\ControllerProviderInterface', 'getControllerConfig');
$serviceListener->addServiceManager('ControllerPluginManager', 'controller_plugins', 'Zend\\ModuleManager\\Feature\\ControllerPluginProviderInterface', 'getControllerPluginConfig');
$serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig');
$serviceListener->addServiceManager('ValidatorManager', 'validators', 'Zend\\ModuleManager\\Feature\\ValidatorProviderInterface', 'getValidatorConfig');
$serviceListener->addServiceManager('FilterManager', 'filters', 'Zend\\ModuleManager\\Feature\\FilterProviderInterface', 'getFilterConfig');
$serviceListener->addServiceManager('FormElementManager', 'form_elements', 'Zend\\ModuleManager\\Feature\\FormElementProviderInterface', 'getFormElementConfig');
$serviceListener->addServiceManager('RoutePluginManager', 'route_manager', 'Zend\\ModuleManager\\Feature\\RouteProviderInterface', 'getRouteConfig');
$serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig');
$serviceListener->addServiceManager('HydratorManager', 'hydrators', 'Zend\\ModuleManager\\Feature\\HydratorProviderInterface', 'getHydratorConfig');
$serviceListener->addServiceManager('InputFilterManager', 'input_filters', 'Zend\\ModuleManager\\Feature\\InputFilterProviderInterface', 'getInputFilterConfig');
$serviceListener->addServiceManager('LogProcessorManager', 'log_processors', 'Zend\\ModuleManager\\Feature\\LogProcessorProviderInterface', 'getLogProcessorConfig');
$serviceListener->addServiceManager('LogWriterManager', 'log_writers', 'Zend\\ModuleManager\\Feature\\LogWritersProviderInterface', 'getLogWriterConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例3: createService
/**
* Creates and returns the module manager
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ServiceLocatorInterface $serviceLocator
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'Console\\Service\\ServiceListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ValidatorManager', 'validators', 'Zend\\ModuleManager\\Feature\\ValidatorProviderInterface', 'getValidatorConfig');
$serviceListener->addServiceManager('FilterManager', 'filters', 'Zend\\ModuleManager\\Feature\\FilterProviderInterface', 'getFilterConfig');
$serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig');
$serviceListener->addServiceManager('SerializerAdapterManager', 'serializers', 'Zend\\ModuleManager\\Feature\\SerializerProviderInterface', 'getSerializerConfig');
$serviceListener->addServiceManager('HydratorManager', 'hydrators', 'Zend\\ModuleManager\\Feature\\HydratorProviderInterface', 'getHydratorConfig');
$serviceListener->addServiceManager('InputFilterManager', 'input_filters', 'Zend\\ModuleManager\\Feature\\InputFilterProviderInterface', 'getInputFilterConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例4: getItem
public function getItem($itemClass = null)
{
if (!$itemClass && $this->item) {
return $this->item;
}
if (!$itemClass) {
$itemClass = $this->getItemClass();
}
if ($this->serviceLocator->has($itemClass)) {
if ($itemClass == $this->getItemClass()) {
return $this->item = $this->serviceLocator->get($itemClass);
} else {
return $this->serviceLocator->get($itemClass);
}
}
$model =& $this;
$this->serviceLocator->setFactory($itemClass, function (ServiceLocatorInterface $serviceLocator) use($itemClass, $model) {
$item = new $itemClass();
$item->setModel($model);
return $item;
});
if ($itemClass == $this->getItemClass()) {
return $this->item = $this->serviceLocator->get($itemClass);
}
return $this->serviceLocator->get($itemClass);
}
示例5: createService
/**
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
* @return \Doctrine\ODM\MongoDB\DocumentManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$serviceLocator->setAllowOverride(true);
$serviceLocator->setFactory('doctrine.configuration.odm_default', new ConfigurationFactory('odm_default'));
$serviceLocator->setAllowOverride(false);
$dm = $serviceLocator->get('doctrine.documentmanager.odm_default');
$dm->getSchemaManager()->ensureIndexes();
return $dm;
}
示例6: createDelegatorWithName
/**
*
* @param ServiceLocatorInterface $serviceLocator
* @param string $name
* @param string $requestedName
* @param Closure $callback
* @return ModuleManager
*/
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
{
/* @var $serviceLocator ServiceManager */
$serviceLocator->setFactory('ModuleListenerManager', 'ZfExtra\\ModuleManager\\Service\\ModuleListenerManagerFactory');
/* @var $moduleManager ModuleManager */
$moduleManager = $callback();
$moduleListenerManager = $serviceLocator->get('ModuleListenerManager');
$listeners = $moduleListenerManager->getCanonicalNames();
foreach ($listeners as $listener) {
$moduleListenerManager->get($listener)->attach($moduleManager->getEventManager());
}
return $moduleManager;
}
示例7: createService
/**
* {@inheritDoc}
*
* @return AbstractPlugin
*/
public function createService(ServiceLocatorInterface $plugins)
{
if (!$plugins instanceof AbstractPluginManager) {
throw new \BadMethodCallException('jQuery plugin factory is meant to be used ' . 'only with a plugin manager');
}
$services = $plugins->getServiceLocator();
$pluginClass = $this->pluginClass;
$plugin = new $pluginClass($this->getCreationOptions($services));
if ($plugin instanceof JQueryPluginableInterface) {
foreach ($plugin->getPlugins() as $name => $options) {
if (!$plugins->has($name)) {
$plugins->setFactory($name, JQueryPluginFactory::class);
}
}
}
return $plugin;
}
示例8: createService
/**
* Creates and returns the module manager.
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ServiceLocatorInterface $serviceLocator
*
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'PPI\\Framework\\ServiceManager\\Factory\\ServiceListenerFactory');
}
$config = $serviceLocator->get('ApplicationConfig');
$defaultListeners = $serviceLocator->get('ModuleDefaultListener');
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('RoutePluginManager', 'route_manager', 'Zend\\ModuleManager\\Feature\\RouteProviderInterface', 'getRouteConfig');
$modules = isset($config['modules']['active_modules']) ? $config['modules']['active_modules'] : array();
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($modules, $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}
示例9: createService
/**
* Creates and returns the module manager
*
* Instantiates the default module listeners, providing them configuration
* from the "module_listener_options" key of the ApplicationConfig
* service. Also sets the default config glob path.
*
* Module manager is instantiated and provided with an EventManager, to which
* the default listener aggregate is attached. The ModuleEvent is also created
* and attached to the module manager.
*
* @param ServiceLocatorInterface $serviceLocator
* @return ModuleManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator->has('ServiceListener')) {
$serviceLocator->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
}
$configuration = $serviceLocator->get('ApplicationConfig');
$listenerOptions = new ListenerOptions($configuration['module_listener_options']);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
$serviceListener = $serviceLocator->get('ServiceListener');
$serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig');
$serviceListener->addServiceManager('ControllerLoader', 'controllers', 'Zend\\ModuleManager\\Feature\\ControllerProviderInterface', 'getControllerConfig');
$serviceListener->addServiceManager('ControllerPluginManager', 'controller_plugins', 'Zend\\ModuleManager\\Feature\\ControllerPluginProviderInterface', 'getControllerPluginConfig');
$serviceListener->addServiceManager('ViewHelperManager', 'view_helpers', 'Zend\\ModuleManager\\Feature\\ViewHelperProviderInterface', 'getViewHelperConfig');
$events = $serviceLocator->get('EventManager');
$events->attach($defaultListeners);
$events->attach($serviceListener);
$moduleEvent = new ModuleEvent();
$moduleEvent->setParam('ServiceManager', $serviceLocator);
$moduleManager = new ModuleManager($configuration['modules'], $events);
$moduleManager->setEvent($moduleEvent);
return $moduleManager;
}