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


PHP ServiceManager::setService方法代码示例

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


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

示例1: setupPluginManager

    public function setupPluginManager($config = array())
    {
        $services = new ServiceManager();

        $services->setService('Config', $config);

        $metadataMap = $this->getMock('ZF\Hal\Metadata\MetadataMap');
        $metadataMap
            ->expects($this->once())
            ->method('getHydratorManager')
            ->will($this->returnValue(new HydratorPluginManager()));

        $services->setService('ZF\Hal\MetadataMap', $metadataMap);

        $this->pluginManager = $this->getMock('Zend\ServiceManager\AbstractPluginManager');

        $this->pluginManager
            ->expects($this->at(1))
            ->method('get')
            ->with('ServerUrl')
            ->will($this->returnValue(new ServerUrl()));

        $this->pluginManager
            ->expects($this->at(2))
            ->method('get')
            ->with('Url')
            ->will($this->returnValue(new Url()));

        $this->pluginManager
            ->expects($this->any())
            ->method('getServiceLocator')
            ->will($this->returnValue($services));
    }
开发者ID:jbarentsen,项目名称:drb,代码行数:33,代码来源:HalViewHelperFactoryTest.php

示例2: 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

示例3: prepare

 protected function prepare($config)
 {
     $services = $this->services = new ServiceManager();
     $services->setAllowOverride(true);
     $services->setService('Config', $config);
     $connection = $this->getMock('AMQPConnection', array(), array(), '', false);
     $channel = $this->getMock('AMQPChannel', array(), array(), '', false);
     $channel->expects($this->any())->method('getPrefetchCount')->will($this->returnValue(10));
     $queue = $this->getMock('AMQPQueue', array(), array(), '', false);
     $queue->expects($this->any())->method('getChannel')->will($this->returnValue($channel));
     $queueFactory = $this->getMock('HumusAmqpModule\\QueueFactory');
     $queueFactory->expects($this->any())->method('create')->will($this->returnValue($queue));
     $connectionManager = $this->getMock('HumusAmqpModule\\PluginManager\\Connection');
     $connectionManager->expects($this->any())->method('get')->with('default')->willReturn($connection);
     $dependentComponent = new ConnectionAbstractServiceFactory();
     $this->services->setService('HumusAmqpModule\\PluginManager\\Connection', $cm = new ConnectionPluginManager());
     $cm->addAbstractFactory($dependentComponent);
     $cm->setServiceLocator($this->services);
     $components = $this->components = new TestAsset\RpcClientAbstractServiceFactory();
     $components->setChannelMock($channel);
     $components->setQueueFactory($queueFactory);
     $this->services->setService('HumusAmqpModule\\PluginManager\\RpcClient', $rpccm = new RpcClientPluginManager());
     $rpccm->addAbstractFactory($components);
     $rpccm->setServiceLocator($this->services);
 }
开发者ID:vitapublic,项目名称:HumusAmqpModule,代码行数:25,代码来源:RpcClientAbstractServiceFactoryTest.php

示例4: testCanCreateViaServiceManager

 public function testCanCreateViaServiceManager()
 {
     $sm = new ServiceManager(['factories' => ['ZfAnnotation\\AnnotationReader' => AnnotationReaderFactory::class, 'ClassParser' => ClassParserFactory::class]]);
     $sm->setService('EventManager', new EventManager());
     $sm->setService('Config', $this->config);
     $this->assertInstanceOf(ClassParser::class, $sm->get('ClassParser'));
 }
开发者ID:alex-oleshkevich,项目名称:zf-annotations,代码行数:7,代码来源:ClassParserCreateFactoryTest.php

示例5: shouldReturnAListOfBreweries

 /**
  * @test
  */
 public function shouldReturnAListOfBreweries()
 {
     $entityManagerMock = $this->getMock('\\Doctrine\\ORM\\EntityManager', array('getRepository'), array(), '', false);
     $this->sm->setService('doctrine.entitymanager.orm_default', $entityManagerMock);
     $breweryRepoMock = $this->getMockBuilder('\\Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     // Mock the entity manager to return
     // a mock brewery repo
     $entityManagerMock->expects($this->once())->method('getRepository')->with('RestApi\\Model\\Brewery')->will($this->returnValue($breweryRepoMock));
     $summitBrewery = new Brewery();
     $summitBrewery->setName('Summit Brewery');
     $summitBrewery->setCity('St. Paul, MN');
     $summitBrewery->setWebsite('www.summitbrewery.com');
     $summitEPA = new Beer();
     $summitEPA->setName('Summit EPA');
     $summitEPA->setStyle('EPA');
     $summitEPA->setIbu(45);
     $summitBrewery->addBeer($summitEPA);
     $harrietBrewing = new Brewery();
     $harrietBrewing->setName('Harriet Brewing');
     $harrietBrewing->setCity('Minneapolis, MN');
     $harrietBrewing->setWebsite('www.harrietbrewing.com');
     // Mock the brewery repo to return our stub data
     $breweryRepoMock->expects($this->once())->method('findAll')->will($this->returnValue(array($summitBrewery, $harrietBrewing)));
     // Make GET request to /breweries/
     $this->dispatch('/breweries/', 'GET');
     $response = $this->getResponse()->getContent();
     // Test response is successful
     $this->assertResponseStatusCode(200);
     // Test JSON response is serialized brewery data
     $this->assertJsonStringEqualsJsonString(json_encode(array(array('name' => 'Summit Brewery', 'city' => 'St. Paul, MN', 'website' => 'www.summitbrewery.com', 'beers' => array(array('name' => 'Summit EPA', 'style' => 'EPA', 'ibu' => 45))), array('name' => 'Harriet Brewing', 'city' => 'Minneapolis, MN', 'website' => 'www.harrietbrewing.com'))), $response);
 }
开发者ID:eschwartz,项目名称:zend-rest-api-tutorial,代码行数:34,代码来源:BreweryRestControllerTest.php

示例6: testOnDispatch

 public function testOnDispatch()
 {
     // Create MvcEvent
     $e = new MvcEvent();
     $e->setViewModel(new ViewModel());
     $rm = new RouteMatch([]);
     $rm->setParam('controller', 'Application\\Controller\\Download');
     $e->setRouteMatch($rm);
     $e->setTarget(new DownloadController([]));
     // Create EntityManager and EntityRepository
     $moduleDetail = new ModuleList();
     $moduleDetail->setModuleDesc('Pretty description');
     $repo = $this->prophesize('Doctrine\\ORM\\EntityRepository');
     $repo->findOneBy(['moduleName' => 'Application'])->willReturn($moduleDetail);
     $em = $this->prophesize('Doctrine\\ORM\\EntityManager');
     $em->getRepository('Application\\Entity\\ModuleList')->willReturn($repo);
     $this->sm->setService('Doctrine\\ORM\\EntityManager', $em->reveal());
     // Create ViewHelperManager
     $headTitle = new HeadTitle();
     $vhm = new HelperPluginManager();
     $vhm->setService('headTitle', $headTitle);
     $this->sm->setService('ViewHelperManager', $vhm);
     $this->module->onDispatch($e);
     $fbMeta = $e->getViewModel()->getVariable('fbMeta');
     $this->assertEquals(sprintf('%s-Real Live Learn ZF2', $moduleDetail->getModuleDesc()), $fbMeta['title']);
     $this->assertEquals(sprintf('%s-', $moduleDetail->getModuleDesc()), $fbMeta['description']);
 }
开发者ID:shitikovkirill,项目名称:LearnZF2,代码行数:27,代码来源:ModuleTest.php

示例7: test_it_injects_an_output_writer

 public function test_it_injects_an_output_writer()
 {
     $this->service_manager->setService('Config', ['migrations' => ['foo' => ['dir' => __DIR__, 'namespace' => 'Foo', 'adapter' => 'fooDb', 'show_log' => true]]]);
     $factory = new MigrationAbstractFactory();
     $instance = $factory->createServiceWithName($this->service_manager, 'migrations.migration.foo', 'asdf');
     $this->assertInstanceOf(OutputWriter::class, $instance->getOutputWriter(), "factory should inject a " . OutputWriter::class);
 }
开发者ID:dpoltoratsky,项目名称:ZfSimpleMigrations,代码行数:7,代码来源:MigrationAbstractFactoryTest.php

示例8: testCreateService

 public function testCreateService()
 {
     $this->sm->setService('Matryoshka\\Model\\ModelManager', $this->mm);
     $this->mm->setServiceLocator($this->sm);
     $model = $this->factory->createService($this->mm);
     $this->assertInstanceOf('Matryoshka\\Module\\Controller\\Plugin\\Model', $model);
 }
开发者ID:ripaclub,项目名称:zf2-matryoshka-module,代码行数:7,代码来源:ModelFactoryTest.php

示例9: setUp

 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  */
 public function setUp()
 {
     parent::setUp();
     static::$sent = 0;
     $this->serviceManager = new ServiceManager();
     $this->serviceManager->setService('Configuration', $this->dataConfig)->setService('SiteInfo', new SiteInfo($this->dataSiteInfo))->setAlias('Zork\\Db\\SiteInfo', 'SiteInfo')->setFactory('Zork\\Mail\\Service', 'Zork\\Mail\\ServiceFactory');
 }
开发者ID:gridguyz,项目名称:zork,代码行数:11,代码来源:ServiceTest.php

示例10: testCreateService

 public function testCreateService()
 {
     $this->serviceLocator->setService('doctrine.orm_cmd.validate_schema', $this->command);
     $this->serviceLocator->setService('Request', $this->request);
     $actual = $this->sut->createService($this->serviceLocator);
     self::assertInstanceOf(CheckCommand::class, $actual);
 }
开发者ID:abacaphiliac,项目名称:doctrine-orm-diagnostics-module,代码行数:7,代码来源:CheckSchemaFactoryTest.php

示例11: setUp

 public function setUp()
 {
     $addressService = $this->getMockBuilder('Ajasta\\Address\\Service\\AddressService')->disableOriginalConstructor()->getMock();
     $this->serviceLocator = new ServiceManager();
     $this->serviceLocator->setService('Ajasta\\Address\\Service\\AddressService', $addressService);
     $this->serviceLocator->setService('Ajasta\\Locale', 'en-US');
 }
开发者ID:DavidHavl,项目名称:Ajasta,代码行数:7,代码来源:CountrySelectFactoryTest.php

示例12: testCreateConsumerThrowsExceptionOnInvalidLogger

 /**
  * @expectedException \HumusAmqpModule\Exception\InvalidArgumentException
  * @expectedExceptionMessage The logger invalid stuff is not configured
  */
 public function testCreateConsumerThrowsExceptionOnInvalidLogger()
 {
     $config = $this->services->get('Config');
     $config['humus_amqp_module']['rpc_servers']['test-rpc-server']['logger'] = 'invalid stuff';
     $this->services->setService('Config', $config);
     $this->components->createServiceWithName($this->services, 'test-rpc-server', 'test-rpc-server');
 }
开发者ID:vitapublic,项目名称:HumusAmqpModule,代码行数:11,代码来源:RpcServerAbstractServiceFactoryTest.php

示例13: __construct

 public function __construct()
 {
     $this->config = (include 'config/application.config.php');
     $this->sm = new ServiceManager(new Service\ServiceManagerConfig($this->config));
     $this->sm->setService('ApplicationConfig', $this->config);
     $this->sm->get('ModuleManager')->loadModules();
 }
开发者ID:usban,项目名称:entilocali,代码行数:7,代码来源:FixtureServiceAbstract.php

示例14: testWillNotInstantiateConfigWithInvalidNamingStrategyReference

 public function testWillNotInstantiateConfigWithInvalidNamingStrategyReference()
 {
     $config = array('doctrine' => array('configuration' => array('test_default' => array('naming_strategy' => 'test_naming_strategy'))));
     $this->serviceManager->setService('Config', $config);
     $this->setExpectedException('Zend\\ServiceManager\\Exception\\InvalidArgumentException');
     $this->factory->createService($this->serviceManager);
 }
开发者ID:antoinealej,项目名称:TibetWebsite,代码行数:7,代码来源:ConfigurationFactoryTest.php

示例15: 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


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