本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::create方法的具体用法?PHP ServiceManager::create怎么用?PHP ServiceManager::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCommands
/**
* Gets list of command instances
*
* @return \Symfony\Component\Console\Command\Command[]
* @throws \Exception
*/
public function getCommands()
{
$commands = [];
foreach ($this->getCommandsClasses() as $class) {
if (class_exists($class)) {
$commands[] = $this->serviceManager->create($class);
} else {
throw new \Exception('Class ' . $class . ' does not exist');
}
}
return $commands;
}
示例2: testAbstractFactoryNotUsedIfNotAbleToCreate
/**
* @covers Zend\ServiceManager\ServiceManager::canCreateFromAbstractFactory
* @covers Zend\ServiceManager\ServiceManager::create
*/
public function testAbstractFactoryNotUsedIfNotAbleToCreate()
{
$service = new \stdClass();
$af1 = $this->getMock('Zend\\ServiceManager\\AbstractFactoryInterface');
$af1->expects($this->any())->method('canCreateServiceWithName')->will($this->returnValue(true));
$af1->expects($this->any())->method('createServiceWithName')->will($this->returnValue($service));
$af2 = $this->getMock('Zend\\ServiceManager\\AbstractFactoryInterface');
$af2->expects($this->any())->method('canCreateServiceWithName')->will($this->returnValue(false));
$af2->expects($this->never())->method('createServiceWithName');
$this->serviceManager->addAbstractFactory($af1);
$this->serviceManager->addAbstractFactory($af2);
$this->assertSame($service, $this->serviceManager->create('test'));
}
示例3: newEntityManager
/**
* Create new entity manager
*
* @return \Doctrine\ORM\EntityManager
*/
public function newEntityManager()
{
$newEntityManager = $this->locator->create('doctrine.entitymanager.orm_default');
$this->entityManager = $newEntityManager;
foreach ($this->locator->getCanonicalNames() as $alias => $canonicalName) {
if (strstr($alias, '\\Service\\')) {
$service = $this->locator->get($alias);
if ($service instanceof AbstractService) {
$service->setObjectManager($newEntityManager);
}
}
}
return $newEntityManager;
}
示例4: testRegistersAutoloader
public function testRegistersAutoloader()
{
$autoloaders = spl_autoload_functions();
$serviceManager = new ServiceManager();
$namespace = 'ZendTestProxy' . uniqid();
$serviceManager->setService('Config', array('lazy_services' => array('class_map' => array('foo' => __CLASS__), 'proxies_namespace' => $namespace)));
$serviceManager->setFactory('foo-delegator', 'Zend\\ServiceManager\\Proxy\\LazyServiceFactoryFactory');
$serviceManager->create('foo-delegator');
$currentAutoloaders = spl_autoload_functions();
$proxyAutoloader = end($currentAutoloaders);
$this->assertCount(count($autoloaders) + 1, $currentAutoloaders);
$this->assertInstanceOf('ProxyManager\\Autoloader\\AutoloaderInterface', $proxyAutoloader);
spl_autoload_unregister($proxyAutoloader);
}
示例5: testDelegatorFromCallback
public function testDelegatorFromCallback()
{
$realService = $this->getMock('stdClass', array(), array(), 'RealService');
$delegator = $this->getMock('stdClass', array(), array(), 'Delegator');
$delegatorFactoryCallback = function ($serviceManager, $cName, $rName, $callback) use($delegator) {
$delegator->real = call_user_func($callback);
return $delegator;
};
$this->serviceManager->setFactory('foo-service', function () use($realService) {
return $realService;
});
$this->serviceManager->addDelegator('foo-service', $delegatorFactoryCallback);
$service = $this->serviceManager->create('foo-service');
$this->assertSame($delegator, $service);
$this->assertSame($realService, $service->real);
}