本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::has方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::has方法的具体用法?PHP ServiceManager::has怎么用?PHP ServiceManager::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHasServiceWithoutConfig
public function testHasServiceWithoutConfig()
{
$this->serviceManager = new ServiceManager\ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['AclMan\\Storage\\StorageFactory']]));
$this->assertFalse($this->serviceManager->has('AclStorage'));
$this->serviceManager = new ServiceManager\ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['AclMan\\Storage\\StorageFactory']]));
$this->serviceManager->setService('Config', []);
$this->assertFalse($this->serviceManager->has('AclStorage'));
}
示例2: testMongoAdapterAbstractServiceFactorEmptyConfig
public function testMongoAdapterAbstractServiceFactorEmptyConfig()
{
$this->serviceManager = new ServiceManager\ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Storage\\Adapter\\Mongo\\MongoAdapterAbstractServiceFactory', 'ImgMan\\Storage\\Adapter\\Mongo\\MongoDbAbstractServiceFactory']]));
$this->assertFalse($this->serviceManager->has('ImgMan\\Storage\\Mongo'));
$this->serviceManager = new ServiceManager\ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Storage\\Adapter\\Mongo\\MongoAdapterAbstractServiceFactory', 'ImgMan\\Storage\\Adapter\\Mongo\\MongoDbAbstractServiceFactory']]));
$this->serviceManager->setService('Config', []);
$this->assertFalse($this->serviceManager->has('ImgMan\\Storage\\Mongo'));
}
示例3: testEmptyConfig
public function testEmptyConfig()
{
$this->serviceManager = new ServiceManager\ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Apigility\\ImgManConnectedResourceAbstractFactory']]));
$this->assertFalse($this->serviceManager->has('ImgmanApigility\\ConnectedResource1'));
$this->serviceManager = new ServiceManager\ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Apigility\\ImgManConnectedResourceAbstractFactory']]));
$this->serviceManager->setService('Config', []);
$this->assertFalse($this->serviceManager->has('ImgmanApigility\\ConnectedResource1'));
}
示例4: testCreateService
public function testCreateService()
{
$config = ['mailman' => ['Mandrill\\Complete' => ['default_sender' => 'test@mail.com', 'additional_info' => ['some' => 'thing'], 'transport' => ['type' => 'mandrill', 'options' => ['api_key' => 'MYSECRETMANDRILLKEY', 'sub_account' => 'my-optional-subaccount-if-any']]]]];
$this->sManager->setService('Config', $config);
$this->assertTrue($this->sManager->has('Mandrill\\Complete'));
$mailService = $this->sManager->get('Mandrill\\Complete');
$this->assertInstanceOf('MailMan\\Service\\MailService', $mailService);
}
示例5: testServiceIntegrity
/**
* Check if all configured services can be created
*
* @dataProvider provideServicesToCheck
*/
public function testServiceIntegrity($serviceName)
{
$this->assertTrue(self::$serviceManager->has($serviceName));
$object = self::$serviceManager->get($serviceName);
if (class_exists($serviceName)) {
$this->assertInstanceOf($serviceName, $object);
}
}
示例6: testMongoDbAbstractServiceFactory
public function testMongoDbAbstractServiceFactory()
{
$this->assertTrue($this->serviceManager->has('MongoDb'));
$this->assertInstanceOf('MongoDb', $this->serviceManager->get('MongoDb'));
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Storage\\Adapter\\Mongo\\MongoDbAbstractServiceFactory']]));
$this->assertFalse($this->serviceManager->has('MongoDb'));
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Storage\\Adapter\\Mongo\\MongoDbAbstractServiceFactory']]));
$this->serviceManager->setService('Config', []);
$this->assertFalse($this->serviceManager->has('MongoDb'));
}
示例7: testFileSystemAbstractFactoryService
public function testFileSystemAbstractFactoryService()
{
$this->assertTrue($this->serviceManager->has('ImgMan\\Storage\\FileSystem'));
$this->assertInstanceOf('ImgMan\\Storage\\StorageInterface', $this->serviceManager->get('ImgMan\\Storage\\FileSystem'));
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Storage\\Adapter\\FileSystem\\FileSystemAbstractServiceFactory']]));
$this->assertFalse($this->serviceManager->has('ImgMan\\Storage\\FileSystem'));
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Storage\\Adapter\\FileSystem\\FileSystemAbstractServiceFactory']]));
$this->serviceManager->setService('Config', []);
$this->assertFalse($this->serviceManager->has('ImgMan\\Storage\\FileSystem'));
}
示例8: testServiceFactoryHas
public function testServiceFactoryHas()
{
$serviceLocator = $this->serviceManager;
$this->assertFalse($serviceLocator->has('ImgMan\\Service\\Test0'));
$this->assertTrue($serviceLocator->has('ImgMan\\Service\\Test1'));
$this->assertTrue($serviceLocator->has('ImgMan\\Service\\Test2'));
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Service\\ImageServiceAbstractFactory']]));
$this->assertFalse($this->serviceManager->has('ImgMan\\Service\\Test2'));
$this->serviceManager = new ServiceManager(new ServiceManagerConfig(['abstract_factories' => ['ImgMan\\Service\\ImageServiceAbstractFactory']]));
$this->serviceManager->setService('Config', []);
$this->assertFalse($this->serviceManager->has('ImgMan\\Service\\Test2'));
}
示例9: testBootstrapRecognizesServiceLocatorConfig
public function testBootstrapRecognizesServiceLocatorConfig()
{
$eventPublisher = $this->getMockBuilder(ServiceLocatorAwareEventPublisher::CLASS)->disableOriginalConstructor()->getMock();
$serviceLocator = new ServiceManager();
$domainManager = new DomainManager($eventPublisher, $serviceLocator);
$domainManager->registerDomain(new ExampleDomain());
$domainManager->bootstrap();
$this->assertTrue($serviceLocator->has('exampleAlias'));
$this->assertEquals('exampleService', call_user_func($serviceLocator->get('exampleAlias')));
$this->assertTrue($serviceLocator->has('exampleFactory'));
$this->assertEquals('exampleFactory', $serviceLocator->get('exampleFactory'));
$this->assertTrue($serviceLocator->has('exampleService'));
$this->assertEquals('exampleService', call_user_func($serviceLocator->get('exampleService')));
}
示例10: getObjectManager
/**
* getObjectManager
*
* Return the object manager instance.
*
* @param ServiceManager $serviceManager The service manager.
* @param string $objectManagerName The object manager name.
* @param string $serviceName The name of the service being created.
*
* @return ObjectManager
*/
private function getObjectManager(ServiceManager $serviceManager, $objectManagerName, $serviceName)
{
if (!$serviceManager->has($objectManagerName)) {
throw new ServiceNotFoundException(sprintf('The object manager \'%s\' could not be found while creating \'%s\'.', $objectManagerName, $serviceName));
}
return $serviceManager->get($objectManagerName);
}
示例11: onLoadModulesPost
/**
* Use merged configuration to configure service manager
*
* If the merged configuration has a non-empty, array 'service_manager'
* key, it will be passed to a ServiceManager Config object, and
* used to configure the service manager.
*
* @param ModuleEvent $e
* @throws Exception\RuntimeException
* @return void
*/
public function onLoadModulesPost(ModuleEvent $e)
{
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);
foreach ($this->serviceManagers as $key => $sm) {
$smConfig = $this->mergeServiceConfiguration($key, $sm, $config);
if (!$sm['service_manager'] instanceof ServiceManager) {
if (!$this->defaultServiceManager->has($sm['service_manager'])) {
throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
}
$instance = $this->defaultServiceManager->get($sm['service_manager']);
if (!$instance instanceof ServiceManager) {
throw new Exception\RuntimeException(sprintf('Could not find a valid ServiceManager for %s', $sm['service_manager']));
}
$sm['service_manager'] = $instance;
}
$serviceConfig = new ServiceConfig($smConfig);
// The service listener is meant to operate during bootstrap, and, as such,
// needs to be able to override existing configuration.
$allowOverride = $sm['service_manager']->getAllowOverride();
$sm['service_manager']->setAllowOverride(true);
$serviceConfig->configureServiceManager($sm['service_manager']);
$sm['service_manager']->setAllowOverride($allowOverride);
}
}
示例12: has
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = true)
{
if (is_string($name)) {
// internally called with an array [normalizedName, requestedName].
$this->incrementCallCount('has', $name);
}
return parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers);
}
示例13: testCanonicalizeName
/**
* @covers Zend\ServiceManager\ServiceManager::canonicalizeName
*/
public function testCanonicalizeName()
{
$this->serviceManager->setService('foo_bar', new \stdClass());
$this->assertEquals(true, $this->serviceManager->has('foo_bar'));
$this->assertEquals(true, $this->serviceManager->has('foobar'));
$this->assertEquals(true, $this->serviceManager->has('foo-bar'));
$this->assertEquals(true, $this->serviceManager->has('foo/bar'));
$this->assertEquals(true, $this->serviceManager->has('foo bar'));
}
示例14: has
public function has($name)
{
if (parent::has($name)) {
return true;
}
if (preg_match('/doctrine/i', $name)) {
return $this->serviceManager->has($name);
}
return false;
}
示例15: testDiAbstractServiceFactory
public function testDiAbstractServiceFactory()
{
$di = $this->getMock('Zend\\Di\\Di');
$factory = new DiAbstractServiceFactory($di);
$factory->instanceManager()->setConfig('ZendTest\\ServiceManager\\TestAsset\\Bar', array('parameters' => array('foo' => array('a'))));
$this->serviceManager->addAbstractFactory($factory);
$this->assertTrue($this->serviceManager->has('ZendTest\\ServiceManager\\TestAsset\\Bar', true));
$bar = $this->serviceManager->get('ZendTest\\ServiceManager\\TestAsset\\Bar', true);
$this->assertInstanceOf('ZendTest\\ServiceManager\\TestAsset\\Bar', $bar);
}