本文整理汇总了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));
}
示例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();
}
示例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);
}
示例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'));
}
示例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);
}
示例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']);
}
示例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);
}
示例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);
}
示例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');
}
示例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);
}
示例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');
}
示例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');
}
示例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();
}
示例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);
}
示例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);
}
}