本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::addInitializer方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::addInitializer方法的具体用法?PHP ServiceManager::addInitializer怎么用?PHP ServiceManager::addInitializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::addInitializer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateWithInitializerObject
public function testCreateWithInitializerObject()
{
$this->serviceManager->addInitializer(new TestAsset\FooInitializer(array('foo' => 'bar')));
$this->serviceManager->setFactory('foo', function () {
return new \stdClass();
});
$obj = $this->serviceManager->get('foo');
$this->assertEquals('bar', $obj->foo);
}
示例2: createServiceManager
public function createServiceManager(array $config)
{
// create ServiceManager
$serviceManager = new ServiceManager();
// set an initializer for ServiceLocatorAwareInterface
$serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($serviceLocator);
}
});
// add $serviceManger to the config keys so we can configure it
$this->configKeys = ['service_manager' => $serviceManager] + $this->configKeys;
// add the pluginManagers to the ServiceManager
foreach ($this->pluginManagers as $key => $className) {
$serviceManager->setInvokableClass($key, $className);
}
// add Zend\Form's view helpers to the ViewHelperManager
$viewHelperManager = $serviceManager->get('ViewHelperManager');
$vhConfig = new \Zend\Form\View\HelperConfig();
$vhConfig->configureServiceManager($viewHelperManager);
// apply configuration
$this->applyConfig($serviceManager, $config);
return $serviceManager;
}
示例3: configureServiceManager
/**
* Configure the provided service manager instance with the configuration
* in this class.
*
* In addition to using each of the internal properties to configure the
* service manager, also adds an initializer to inject ServiceManagerAware
* and ServiceLocatorAware classes with the service manager.
*
* @param ServiceManager $serviceManager
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->invokables as $name => $class) {
$serviceManager->setInvokableClass($name, $class);
}
foreach ($this->factories as $name => $factoryClass) {
$serviceManager->setFactory($name, $factoryClass);
}
foreach ($this->abstractFactories as $factoryClass) {
$serviceManager->addAbstractFactory($factoryClass);
}
foreach ($this->aliases as $name => $service) {
$serviceManager->setAlias($name, $service);
}
foreach ($this->shared as $name => $value) {
$serviceManager->setShared($name, $value);
}
$serviceManager->addInitializer(function ($instance) use($serviceManager) {
if ($instance instanceof EventManagerAwareInterface) {
if ($instance->getEventManager() instanceof EventManagerInterface) {
$instance->getEventManager()->setSharedManager($serviceManager->get('SharedEventManager'));
} else {
$instance->setEventManager($serviceManager->get('EventManager'));
}
}
});
$serviceManager->addInitializer(function ($instance) use($serviceManager) {
if ($instance instanceof ServiceManagerAwareInterface) {
$instance->setServiceManager($serviceManager);
}
});
$serviceManager->addInitializer(function ($instance) use($serviceManager) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($serviceManager);
}
});
$serviceManager->setService('ServiceManager', $serviceManager);
}
示例4: testShouldRaiseExceptionIfInitializerClassIsNotAnInitializerInterfaceImplementation
public function testShouldRaiseExceptionIfInitializerClassIsNotAnInitializerInterfaceImplementation()
{
$this->setExpectedException('Zend\ServiceManager\Exception\InvalidArgumentException');
$result = $this->serviceManager->addInitializer(get_class($this));
}
示例5: createServiceManager
/**
* Creates a service manager instnace
*
* @param array $config
* @return \Zend\ServiceManager\ServiceManager
*/
public static function createServiceManager(array $config = [])
{
$serviceManager = new ServiceManager(new Config($config));
$serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof ModelManagerAwareInterface) {
$instance->setModelManager($serviceLocator->get('modelmanager'));
}
});
$serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($serviceLocator);
}
});
return $serviceManager;
}
示例6: createServiceManager
public static function createServiceManager($config = [])
{
$serviceManager = new ServiceManager(new Config($config));
$serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof DocumentManagerAwareInterface) {
$instance->setDocumentManager($serviceLocator->get($serviceLocator->get('manifest')['document_manager']));
}
});
$serviceManager->addInitializer(function ($instance, ServiceLocatorInterface $serviceLocator) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($serviceLocator);
}
});
return $serviceManager;
}