本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::setShared方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::setShared方法的具体用法?PHP ServiceManager::setShared怎么用?PHP ServiceManager::setShared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::setShared方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: configureServiceManager
public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
{
$serviceManager->setFactory('A', function () {
return new A();
});
$serviceManager->setShared('A', true);
$serviceManager->setFactory('B', function ($serviceManager) {
return new B($serviceManager->get('A'));
});
$serviceManager->setShared('B', false);
}
示例2: configureServiceManager
public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
{
$serviceManager->setFactory('A', function () {
return new A();
});
$serviceManager->setShared('A', false);
$serviceManager->setFactory('B', function ($serviceManager) {
return new B($serviceManager->get('A'));
});
$serviceManager->setShared('B', false);
$serviceManager->setFactory('C', function ($serviceManager) {
return new C($serviceManager->get('B'));
});
$serviceManager->setShared('C', false);
$serviceManager->setFactory('D', function ($serviceManager) {
return new D($serviceManager->get('C'));
});
$serviceManager->setShared('D', false);
$serviceManager->setFactory('E', function ($serviceManager) {
return new E($serviceManager->get('D'));
});
$serviceManager->setShared('E', false);
$serviceManager->setFactory('F', function ($serviceManager) {
return new F($serviceManager->get('E'));
});
$serviceManager->setShared('F', false);
$serviceManager->setFactory('G', function ($serviceManager) {
return new G($serviceManager->get('F'));
});
$serviceManager->setShared('G', false);
$serviceManager->setFactory('H', function ($serviceManager) {
return new H($serviceManager->get('G'));
});
$serviceManager->setShared('H', false);
$serviceManager->setFactory('I', function ($serviceManager) {
return new I($serviceManager->get('H'));
});
$serviceManager->setShared('I', false);
$serviceManager->setFactory('J', function ($serviceManager) {
return new J($serviceManager->get('I'));
});
$serviceManager->setShared('J', false);
}
示例3: testGetUsesIndivualSharedSettingWhenSetAndDeviatesFromShareByDefaultSetting
/**
* @covers Zend\ServiceManager\ServiceManager::get
*/
public function testGetUsesIndivualSharedSettingWhenSetAndDeviatesFromShareByDefaultSetting()
{
$this->serviceManager->setAllowOverride(true);
$this->serviceManager->setShareByDefault(false);
$this->serviceManager->setInvokableClass('foo', 'ZendTest\\ServiceManager\\TestAsset\\Foo');
$this->serviceManager->setShared('foo', true);
$this->assertSame($this->serviceManager->get('foo'), $this->serviceManager->get('foo'));
$this->serviceManager->setShareByDefault(true);
$this->serviceManager->setInvokableClass('foo', 'ZendTest\\ServiceManager\\TestAsset\\Foo');
$this->serviceManager->setShared('foo', false);
$this->assertNotSame($this->serviceManager->get('foo'), $this->serviceManager->get('foo'));
}
示例4: registerFactory
/**
* Registers a factory wrapping a Slim factory into a ZF2 factory
*
* @param $key
* @param callable $callable
* @param bool $shared
*/
protected function registerFactory($key, callable $callable, $shared = true)
{
$this->sm->setFactory($key, new CallbackWrapper($this, $callable));
$this->sm->setShared($key, $shared);
}
示例5: testSetSharedThrowsExceptionOnUnregisteredService
/**
* @covers Zend\ServiceManager\ServiceManager::setShared
*/
public function testSetSharedThrowsExceptionOnUnregisteredService()
{
$this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotFoundException');
$this->serviceManager->setShared('foo', true);
}
示例6: 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);
}
示例7: build
/**
* @param $config
* @param array $data
* @return array|object|ViewModel
*/
public function build($config, array $data = array())
{
$allOptions = $this->config->getOptions();
$i = 0;
$queue = new \SplQueue();
$queue->enqueue($config);
while ($queue->count() > 0) {
$options = $queue->dequeue();
$options = $this->config->applyInheritance($options);
if (isset($options['viewModel'])) {
$this->serviceLocator->setShared($options['viewModel'], false);
$viewModel = $this->serviceLocator->get($options['viewModel']);
} else {
$viewModel = new ZendViewModel();
}
if ($i == 0) {
$rootViewModel = $viewModel;
}
if (isset($options['template'])) {
$viewModel->setTemplate($options['template']);
}
if (isset($options['capture'])) {
$viewModel->setCaptureTo($options['capture']);
} elseif (isset($options['id'])) {
$viewModel->setCaptureTo($options['id']);
}
if (isset($options['data']['static'])) {
$viewModel->setVariables($options['data']['static']);
}
if (isset($options['data']['fromGlobal'])) {
$globalVar = $options['data']['fromGlobal'];
if (is_array($globalVar)) {
foreach ($globalVar as $globalVarName => $viewVarName) {
$globalVarValue = $this->getVarValue($globalVarName, $data);
$viewModel->setVariable($viewVarName, $globalVarValue);
}
} else {
$globalVarValue = $this->getVarValue($globalVar, $data);
$viewModel->setVariable($globalVar, $globalVarValue);
}
}
if (isset($options['parent'])) {
/** @var ViewModel $parent */
$parent = $options['parent'];
$parent->addChild($viewModel, $viewModel->captureTo(), true);
if (isset($options['data']['fromParent'])) {
$varFromParent = $options['data']['fromParent'];
$parentVars = $parent->getVariables();
if (is_array($varFromParent)) {
foreach ($varFromParent as $varFromParentName => $viewVarName) {
$fromParentVal = $this->getVarValue($varFromParentName, $parentVars);
if ($fromParentVal === null) {
$fromParentVal = $parent->getVariable($varFromParentName);
}
if (is_array($viewVarName)) {
$dataFromParent = [];
foreach ($viewVarName as $varName) {
$dataFromParent[$varName] = $fromParentVal;
}
} else {
$dataFromParent = [$viewVarName => $fromParentVal];
}
$viewModel->setVariables($dataFromParent);
}
} else {
$viewVarName = $options['data']['fromParent'];
$fromParentVal = $this->getVarValue($viewVarName, $parentVars);
if ($fromParentVal === null) {
$fromParentVal = $parent->getVariable($viewVarName);
}
$viewModel->setVariables([$viewVarName => $fromParentVal]);
}
}
}
if (!empty($options['children'])) {
foreach ($options['children'] as $childId => $child) {
if (is_string($child)) {
$childId = $child;
$child = $allOptions[$child];
}
if (isset($options['childrenDynamicLists'][$childId])) {
continue;
}
$child['id'] = $childId;
$child['parent'] = $viewModel;
$queue->enqueue($child);
}
}
if (isset($options['childrenDynamicLists'])) {
foreach ($options['childrenDynamicLists'] as $childName => $listName) {
$list = $viewModel->getVariable($listName);
if ($list === null) {
throw new \UnexpectedValueException("Cannot build children list of '{$childName}' by '{$listName}' list . View does not contain variable '{$listName}'.");
}
if (!is_array($list) && !$list instanceof \Traversable) {
//.........这里部分代码省略.........