当前位置: 首页>>代码示例>>PHP>>正文


PHP ServiceManager::setFactory方法代码示例

本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::setFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::setFactory方法的具体用法?PHP ServiceManager::setFactory怎么用?PHP ServiceManager::setFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\ServiceManager\ServiceManager的用法示例。


在下文中一共展示了ServiceManager::setFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setup

 public function setup()
 {
     parent::setup();
     $config = (include 'config/application.config.php');
     $config['module_listener_options']['config_static_paths'] = array(getcwd() . '/config/test.config.php');
     if (file_exists(__DIR__ . '/config/test.config.php')) {
         $moduleConfig = (include __DIR__ . '/config/test.config.php');
         array_unshift($config['module_listener_options']['config_static_paths'], $moduleConfig);
     }
     $this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
     $this->serviceManager->setService('ApplicationConfig', $config);
     $this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
     $moduleManager = $this->serviceManager->get('ModuleManager');
     $moduleManager->loadModules();
     $this->routes = array();
     foreach ($moduleManager->getModules() as $m) {
         $moduleConfig = (include __DIR__ . '/../../../../' . ucfirst($m) . '/config/module.config.php');
         if (isset($moduleConfig['router'])) {
             foreach ($moduleConfig['router']['routes'] as $key => $name) {
                 $this->routes[$key] = $name;
             }
         }
     }
     $this->serviceManager->setAllowOverride(true);
     $this->application = $this->serviceManager->get('Application');
     $this->event = new MvcEvent();
     $this->event->setTarget($this->application);
     $this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
     $this->createDatabase();
 }
开发者ID:alfredocoj,项目名称:blogzf2tutorial,代码行数:30,代码来源:TestCase.php

示例2: setup

 public function setup()
 {
     parent::setup();
     $pathDir = getcwd() . "/";
     $config = (include $pathDir . 'config/application.config.php');
     $this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
     $this->serviceManager->setService('ApplicationConfig', $config);
     $this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
     $moduleManager = $this->serviceManager->get('ModuleManager');
     $moduleManager->loadModules();
     $this->routes = array();
     $this->modules = $moduleManager->getModules();
     foreach ($this->filterModules() as $m) {
         $moduleConfig = (include $pathDir . 'module/' . ucfirst($m) . '/config/module.config.php');
         if (isset($moduleConfig['router'])) {
             foreach ($moduleConfig['router']['routes'] as $key => $name) {
                 $this->routes[$key] = $name;
             }
         }
     }
     $this->serviceManager->setAllowOverride(true);
     $this->application = $this->serviceManager->get('Application');
     $this->event = new MvcEvent();
     $this->event->setTarget($this->application);
     $this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
     $this->em = $this->serviceManager->get('Doctrine\\ORM\\EntityManager');
     foreach ($this->filterModules() as $m) {
         $this->createDatabase($m);
     }
 }
开发者ID:argentinaluiz,项目名称:Learning-ZF2,代码行数:30,代码来源:TestCase.php

示例3: 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);
 }
开发者ID:lucatume,项目名称:php-dependency-injection-benchmarks,代码行数:11,代码来源:test5.php

示例4: getServiceManager

 /**
  * Builds a new service manager
  */
 public static function getServiceManager()
 {
     $serviceManager = new ServiceManager(new ServiceManagerConfig(isset(static::$config['service_manager']) ? static::$config['service_manager'] : array()));
     $serviceManager->setService('ApplicationConfig', static::$config);
     $serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
     $serviceManager->setFactory('ModuleListener', 'Zend\\Mvc\\Service\\ModuleListenerFactory');
     /** @var $moduleManager \Zend\ModuleManager\ModuleManager */
     $moduleManager = $serviceManager->get('ModuleManager');
     $moduleManager->loadModules();
     //$serviceManager->setAllowOverride(true);
     return $serviceManager;
 }
开发者ID:neobytec,项目名称:SlmQueueDoctrine,代码行数:15,代码来源:ServiceManagerFactory.php

示例5: testWillInstantiateFromFQCN

 public function testWillInstantiateFromFQCN()
 {
     $name = 'testFactory';
     $factory = new AuthenticationServiceFactory($name);
     $objectManager = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager');
     $serviceManager = new ServiceManager();
     $serviceManager->setService('Configuration', array('doctrine' => array('authentication' => array($name => array('objectManager' => $objectManager, 'identityClass' => 'DoctrineModuleTest\\Authentication\\Adapter\\TestAsset\\IdentityObject', 'identityProperty' => 'username', 'credentialProperty' => 'password')))));
     $serviceManager->setFactory('doctrine.authenticationadapter.' . $name, new AdapterFactory($name));
     $serviceManager->setFactory('doctrine.authenticationstorage.' . $name, new StorageFactory($name));
     $authenticationService = $factory->createService($serviceManager);
     $this->assertInstanceOf('Zend\\Authentication\\AuthenticationService', $authenticationService);
 }
开发者ID:antoinealej,项目名称:TibetWebsite,代码行数:12,代码来源:AuthenticationServiceFactoryTest.php

示例6: setUp

 public function setUp()
 {
     $formElementManagerFactory = new FormElementManagerFactory();
     $config = new ArrayObject(array('di' => array()));
     $this->services = new ServiceManager();
     $this->services->setService('Zend\\ServiceManager\\ServiceLocatorInterface', $this->services);
     $this->services->setFactory('FormElementManager', $formElementManagerFactory);
     $this->services->setService('Config', $config);
     $this->services->setFactory('Di', new DiFactory());
     $this->services->setFactory('DiAbstractServiceFactory', new DiAbstractServiceFactoryFactory());
     $this->services->setFactory('DiServiceInitializer', new DiServiceInitializerFactory());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:12,代码来源:FormElementManagerFactoryTest.php

示例7: setUp

 public function setUp()
 {
     $loaderFactory = new ControllerLoaderFactory();
     $config = new ArrayObject(array('di' => array()));
     $this->services = new ServiceManager();
     $this->services->setService('Zend\\ServiceManager\\ServiceLocatorInterface', $this->services);
     $this->services->setFactory('ControllerLoader', $loaderFactory);
     $this->services->setService('Config', $config);
     $this->services->setFactory('ControllerPluginManager', new ControllerPluginManagerFactory());
     $this->services->setFactory('Di', new DiFactory());
     $this->services->setFactory('EventManager', new EventManagerFactory());
     $this->services->setInvokableClass('SharedEventManager', 'Zend\\EventManager\\SharedEventManager');
 }
开发者ID:nieldm,项目名称:zf2,代码行数:13,代码来源:ControllerLoaderFactoryTest.php

示例8: testInitLoadsEnvironmentVariablesFromWorkingDirectory

 /**
  * @expectedException \Abacaphiliac\ZendPhpDotEnv\Exception\InvalidWorkingDirectoryPathException
  */
 public function testInitLoadsEnvironmentVariablesFromWorkingDirectory()
 {
     $serviceLocator = new ServiceManager();
     $serviceLocator->setService('ApplicationConfig', array('module_listener_options' => array(), 'modules' => array('Abacaphiliac\\ZendPhpDotEnv')));
     $serviceLocator->setFactory('EventManager', new EventManagerFactory());
     $serviceLocator->setService('SharedEventManager', new SharedEventManager());
     $serviceLocator->setFactory('ServiceListener', '\\Zend\\Mvc\\Service\\ServiceListenerFactory');
     $moduleManagerFactory = new ModuleManagerFactory();
     $moduleManager = $moduleManagerFactory->createService($serviceLocator);
     $module = new Module($constant = null, $variable = null, $file = '.testEnv');
     $module->init($moduleManager);
     $moduleManager->getEventManager()->trigger(new ModuleEvent(ModuleEvent::EVENT_LOAD_MODULE));
 }
开发者ID:abacaphiliac,项目名称:zend-phpdotenv,代码行数:16,代码来源:ModuleTest.php

示例9: setup

 /**
  * Faz o setup dos testes. Executado antes de cada teste
  * @return void
  */
 public function setup()
 {
     $env = getenv('ENV');
     //o jenkins tem configurações especiais
     if (!$env || $env != 'jenkins') {
         putenv("ENV=testing");
         $env = 'testing';
     }
     putenv('PROJECT_ROOT=' . __DIR__ . '/../../../../../');
     parent::setup();
     //arquivo de configuração da aplicação
     $config = (include __DIR__ . '/../../../../../config/tests.config.php');
     $config['module_listener_options']['config_static_paths'] = array();
     //cria um novo ServiceManager
     $this->serviceManager = new ServiceManager(new ServiceManagerConfig(isset($config['service_manager']) ? $config['service_manager'] : array()));
     //configura os serviços básicos no ServiceManager
     $this->serviceManager->setService('ApplicationConfig', $config);
     $this->serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
     //verifica se os módulos possuem rotas configuradas e carrega elas para serem usadas pelo ControllerTestCase
     $moduleManager = $this->serviceManager->get('ModuleManager');
     $moduleManager->loadModules();
     $this->routes = array();
     $testConfig = false;
     //carrega as rotas dos módulos
     foreach ($moduleManager->getLoadedModules() as $m) {
         $moduleConfig = $m->getConfig();
         $this->getModuleRoutes($moduleConfig);
         $moduleName = explode('\\', get_class($m));
         $moduleName = $moduleName[0];
         //verifica se existe um arquivo de configuração específico no módulo para testes
         if (file_exists(getcwd() . '/module/' . ucfirst($moduleName) . '/config/test.config.php')) {
             $testConfig = (include getcwd() . '/module/' . ucfirst($moduleName) . '/config/test.config.php');
             array_unshift($config['module_listener_options']['config_static_paths'], $testConfig[$env]);
         }
     }
     if (!$testConfig) {
         $config['module_listener_options']['config_static_paths'] = array(getcwd() . '/config/tests.config.php');
     }
     $this->config = (include $config['module_listener_options']['config_static_paths'][0]);
     $this->serviceManager->setAllowOverride(true);
     //instancia a aplicação e configura os eventos e rotas
     $this->application = $this->serviceManager->get('Application');
     $this->event = new MvcEvent();
     $this->event->setTarget($this->application);
     $this->event->setApplication($this->application)->setRequest($this->application->getRequest())->setResponse($this->application->getResponse())->setRouter($this->serviceManager->get('Router'));
     $this->entityManager = $this->getEntityManager();
     $this->dropDatabase();
     $this->createDatabase();
 }
开发者ID:evertonteotonio,项目名称:erpphp,代码行数:53,代码来源:TestCase.php

示例10: getServiceLocator

 public function getServiceLocator(array $config = array())
 {
     $serviceLocator = new ServiceManager();
     $serviceLocator->setFactory('MQUtil\\Service\\ShortUrl', 'MQUtil\\Service\\ShortUrlFactory');
     $serviceLocator->setService('config', $config);
     return $serviceLocator;
 }
开发者ID:milqmedia,项目名称:mq-util,代码行数:7,代码来源:ShortenUrlTest.php

示例11: testGet

 public function testGet()
 {
     // Via container
     $this->container->foo = [];
     $this->assertEquals([], $this->container->get('foo'));
     // Via service manager
     $this->sm->setService('foo', new \stdClass());
     $this->sm->setAlias('bar', 'foo');
     $this->assertInstanceOf('stdClass', $this->container->get('bar'));
     $this->sm->setFactory('factory', function (ServiceManager $sm) {
         return $sm->get('bar');
     });
     $this->assertInstanceOf('stdClass', $this->container->get('factory'));
     $this->sm->setInvokableClass('invokable', 'stdClass');
     $this->assertInstanceOf('stdClass', $this->container->get('invokable'));
 }
开发者ID:acelaya,项目名称:slim-container-sm,代码行数:16,代码来源:ContainerTest.php

示例12: getServiceManager

 /**
  * Retrieves a new ServiceManager instance
  *
  * @param  array|null     $configuration
  * @return ServiceManager
  */
 public function getServiceManager(array $configuration = null)
 {
     $configuration = $configuration ?: static::getConfiguration();
     $serviceManager = new ServiceManager(new ServiceManagerConfig(isset($configuration['service_manager']) ? $configuration['service_manager'] : array()));
     $serviceManager->setService('ApplicationConfig', $configuration);
     $serviceManager->setFactory('ServiceListener', 'Zend\\Mvc\\Service\\ServiceListenerFactory');
     return $serviceManager;
 }
开发者ID:Ellipizle,项目名称:LdcZfcUserOAuth2,代码行数:14,代码来源:TestCase.php

示例13: getServiceLocator

 public function getServiceLocator(array $config = array())
 {
     $config = array('mq_locale' => $config);
     $serviceLocator = new ServiceManager();
     $serviceLocator->setFactory('MQLocale\\Locale\\Detector', 'MQLocale\\Service\\DetectorFactory');
     $serviceLocator->setService('config', $config);
     return $serviceLocator;
 }
开发者ID:milqmedia,项目名称:mq-locale,代码行数:8,代码来源:DetectFactoryTest.php

示例14: testConstructedFromConfig

 /**
  * @covers \Zend\Navigation\MvcNavigationFactory
  */
 public function testConstructedFromConfig()
 {
     $argument = new Config\Config(array(array('label' => 'Page 1', 'uri' => 'page1.html'), array('label' => 'Page 2', 'uri' => 'page2.html'), array('label' => 'Page 3', 'uri' => 'page3.html')));
     $factory = new ConstructedNavigationFactory($argument);
     $this->serviceManager->setFactory('Navigation', $factory);
     $container = $this->serviceManager->get('Navigation');
     $this->assertEquals(3, $container->count());
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:11,代码来源:ServiceFactoryTest.php

示例15: testWillInitializeDiAndDiAbstractFactory

 public function testWillInitializeDiAndDiAbstractFactory()
 {
     $serviceManager = new ServiceManager();
     $serviceManager->setService('Config', array('di' => array('')));
     $serviceManager->setFactory('Di', new DiFactory());
     $di = $serviceManager->get('Di');
     $this->assertInstanceOf('Zend\\Di\\Di', $di);
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:8,代码来源:DiFactoryTest.php


注:本文中的Zend\ServiceManager\ServiceManager::setFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。