本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::addAbstractFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::addAbstractFactory方法的具体用法?PHP ServiceManager::addAbstractFactory怎么用?PHP ServiceManager::addAbstractFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::addAbstractFactory方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
Adapter\AdapterFactory::resetAdapterPluginManager();
$this->sm = new ServiceManager();
$this->sm->setService('Config', ['stakhanovist' => ['queue_adapters' => ['ArrayAdapter' => ['adapter' => 'array', 'options' => ['dummyOption' => 'dummyValue']], 'Foo' => ['adapter' => 'array', 'options' => ['dummyOption' => 'dummyValue']]]]]);
$this->sm->addAbstractFactory(QueueAdapterAbstractServiceFactory::class);
}
示例2: setUp
public function setUp()
{
$adapter = new ArrayAdapter();
$adapter->setOptions(['dummyOption' => 'dummyValue']);
$this->sm = new ServiceManager();
$this->sm->setInvokableClass('custom', Adapter\NullAdapter::class);
$this->sm->setService('Config', ['stakhanovist' => ['queues' => ['queueA' => ['name' => 'A', 'adapter' => ['adapter' => 'array', 'options' => ['dummyOption' => 'dummyValue']], 'options' => ['messageClass' => ZendMessage::class]], 'queueB' => ['name' => 'B', 'adapter' => $adapter, 'options' => ['messageClass' => ZendMessage::class]], 'queueC' => ['name' => 'C', 'adapter' => 'custom', 'options' => ['messageClass' => ZendMessage::class]]]]]);
$this->sm->addAbstractFactory(QueueAbstractServiceFactory::class);
}
示例3: testCreateConsumerWithCustomLogger
public function testCreateConsumerWithCustomLogger()
{
$config = array('log' => array('consumer-logger' => array('writers' => array(array('name' => 'stream', 'priority' => 1000, 'options' => array('stream' => sys_get_temp_dir() . '/consumers.log'))))), 'humus_amqp_module' => array('default_connection' => 'default', 'exchanges' => array('demo-exchange' => array('name' => 'demo-exchange', 'type' => 'direct')), 'queues' => array('demo-queue' => array('name' => 'demo-queue', 'exchange' => 'demo-exchange')), 'consumers' => array('test-consumer' => array('connection' => 'default', 'queues' => ['demo-queue'], 'auto_setup_fabric' => false, 'logger' => 'consumer-logger', 'callback' => 'test-callback', 'qos' => array('prefetchCount' => 10)))));
$this->prepare($config);
$this->services->addAbstractFactory(new \Zend\Log\LoggerAbstractServiceFactory());
$this->components->createServiceWithName($this->services, 'test-consumer', 'test-consumer');
}
示例4: testCreateWithCallableAbstractFactory
/**
* @covers Zend\ServiceManager\ServiceManager::create
*/
public function testCreateWithCallableAbstractFactory()
{
$this->serviceManager->addAbstractFactory(function () {
return new TestAsset\Foo();
});
$this->assertInstanceOf('ZendTest\\ServiceManager\\TestAsset\\Foo', $this->serviceManager->get('foo'));
}
示例5: testDuplicateNewInstanceMultipleAbstractFactories
/**
* @covers Zend\ServiceManager\ServiceManager::get
*/
public function testDuplicateNewInstanceMultipleAbstractFactories()
{
$this->serviceManager->setAllowOverride(true);
$this->serviceManager->setShareByDefault(false);
$this->serviceManager->addAbstractFactory('ZendTest\ServiceManager\TestAsset\BarAbstractFactory');
$this->serviceManager->addAbstractFactory('ZendTest\ServiceManager\TestAsset\FooAbstractFactory');
$this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
$this->assertInstanceOf('ZendTest\ServiceManager\TestAsset\Bar', $this->serviceManager->get('bar'));
}
示例6: testPeeringService
public function testPeeringService()
{
$di = new Di();
$di->instanceManager()->setParameters('ZendTest\\ServiceManager\\TestAsset\\Bar', array('foo' => array('a')));
$this->serviceManager->addAbstractFactory(new DiAbstractServiceFactory($di));
$sm = $this->serviceManager->createScopedServiceManager(ServiceManager::SCOPE_PARENT);
$sm->setFactory('di', new DiFactory());
$bar = $sm->get('ZendTest\\ServiceManager\\TestAsset\\Bar', true);
$this->assertInstanceOf('ZendTest\\ServiceManager\\TestAsset\\Bar', $bar);
}
示例7: testCreateZendCache
/**
* @covers \DoctrineModule\Service\CacheFactory::createService
* @group 547
*/
public function testCreateZendCache()
{
$factory = new CacheFactory('phpunit');
$serviceManager = new ServiceManager();
$serviceManager->setAlias('Config', 'Configuration');
$serviceManager->setService('Configuration', ['doctrine' => ['cache' => ['phpunit' => ['class' => 'DoctrineModule\\Cache\\ZendStorageCache', 'instance' => 'my-zend-cache', 'namespace' => 'DoctrineModule']]], 'caches' => ['my-zend-cache' => ['adapter' => ['name' => 'blackhole']]]]);
$serviceManager->addAbstractFactory('Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory');
$cache = $factory->createService($serviceManager);
$this->assertInstanceOf('DoctrineModule\\Cache\\ZendStorageCache', $cache);
}
示例8: init
/**
* Set up the service manager
*
* @return ServiceManager
*/
public function init()
{
$options = $this->getOptions();
$di = $this->getBootstrap()->bootstrap('Di')->getResource('Di');
$doctrineContainer = $this->getBootstrap()->bootstrap('Doctrine')->getResource('Doctrine');
$serviceManager = new ZendServiceManager\ServiceManager(new ZendServiceManager\Config($options));
$serviceManager->setService('Di', $di);
$serviceManager->setService('doctrine.entitymanager.orm_default', $doctrineContainer->getEntityManager());
$serviceManager->addAbstractFactory(new ZendServiceManager\Di\DiAbstractServiceFactory($di));
return $serviceManager;
}
示例9: 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'));
}
示例10: testAbstractFactoriesCanReturnAnyTypeButNull
/**
* @dataProvider getServiceOfVariousTypes
* @param $service
*/
public function testAbstractFactoriesCanReturnAnyTypeButNull($service)
{
$abstractFactory = $this->getMock('Zend\\ServiceManager\\AbstractFactoryInterface');
$abstractFactory->expects($this->any())->method('canCreateServiceWithName')->with($this->serviceManager, 'something', 'something')->will($this->returnValue(true));
$abstractFactory->expects($this->any())->method('createServiceWithName')->with($this->serviceManager, 'something', 'something')->will($this->returnValue($service));
$this->serviceManager->addAbstractFactory($abstractFactory);
if ($service === null) {
try {
$this->serviceManager->get('something');
$this->fail('ServiceManager::get() successfully returned null');
} catch (\Exception $e) {
$this->assertInstanceOf('Zend\\ServiceManager\\Exception\\ServiceNotCreatedException', $e);
}
} else {
$this->assertSame($service, $this->serviceManager->get('something'));
}
}
示例11: configureServiceManager
/**
* Configure the provided service manager instance with the configuration
* in this class.
*
* In addition to using each of the internal properties to configure the
* service manager, also adds an initializer to inject ServiceManagerAware
* and ServiceLocatorAware classes with the service manager.
*
* @param ServiceManager $serviceManager
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->invokables as $name => $class) {
$serviceManager->setInvokableClass($name, $class);
}
foreach ($this->factories as $name => $factoryClass) {
$serviceManager->setFactory($name, $factoryClass);
}
foreach ($this->abstractFactories as $factoryClass) {
$serviceManager->addAbstractFactory($factoryClass);
}
foreach ($this->aliases as $name => $service) {
$serviceManager->setAlias($name, $service);
}
foreach ($this->shared as $name => $value) {
$serviceManager->setShared($name, $value);
}
$serviceManager->addInitializer(function ($instance) use($serviceManager) {
if ($instance instanceof EventManagerAwareInterface) {
if ($instance->getEventManager() instanceof EventManagerInterface) {
$instance->getEventManager()->setSharedManager($serviceManager->get('SharedEventManager'));
} else {
$instance->setEventManager($serviceManager->get('EventManager'));
}
}
});
$serviceManager->addInitializer(function ($instance) use($serviceManager) {
if ($instance instanceof ServiceManagerAwareInterface) {
$instance->setServiceManager($serviceManager);
}
});
$serviceManager->addInitializer(function ($instance) use($serviceManager) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($serviceManager);
}
});
$serviceManager->setService('ServiceManager', $serviceManager);
}
示例12: testWillNotCreateCircularReferences
/**
* @covers Zend\ServiceManager\ServiceManager::createFromAbstractFactory
* @covers Zend\ServiceManager\ServiceManager::has
*/
public function testWillNotCreateCircularReferences()
{
$abstractFactory = new TestAsset\CircularDependencyAbstractFactory();
$sm = new ServiceManager();
$sm->addAbstractFactory($abstractFactory);
$foo = $sm->get('foo');
$this->assertSame($abstractFactory->expectedInstance, $foo);
}