当前位置: 首页>>代码示例>>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;未经允许,请勿转载。