當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ServiceManager::create方法代碼示例

本文整理匯總了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;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:18,代碼來源:CommandList.php

示例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'));
 }
開發者ID:razvansividra,項目名稱:pnlzf2-1,代碼行數:17,代碼來源:ServiceManagerTest.php

示例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;
 }
開發者ID:kristjanAnd,項目名稱:SimpleIV,代碼行數:19,代碼來源:AbstractService.php

示例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);
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:14,代碼來源:LazyServiceFactoryFactoryTest.php

示例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);
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:16,代碼來源:ServiceManagerTest.php


注:本文中的Zend\ServiceManager\ServiceManager::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。