本文整理汇总了PHP中Zend\ServiceManager\ServiceManager::setAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceManager::setAlias方法的具体用法?PHP ServiceManager::setAlias怎么用?PHP ServiceManager::setAlias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\ServiceManager\ServiceManager
的用法示例。
在下文中一共展示了ServiceManager::setAlias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createServiceManager
public function createServiceManager($config)
{
$serviceManager = new ServiceManager();
$serviceManager->setService('Configuration', $config);
$serviceManager->setAlias('Config', 'Configuration');
return $serviceManager;
}
示例2: setup
public function setup()
{
$this->config = new ArrayObject(array('diagnostics' => array()));
$this->sm = new ServiceManager();
$this->sm->setService('console', new ConsoleAdapter());
$this->sm->setService('config', $this->config);
$this->sm->setAlias('configuration', 'config');
$this->mm = new InjectableModuleManager();
$this->sm->setService('modulemanager', $this->mm);
$event = new MvcEvent();
$this->routeMatch = new RouteMatch(array('controller' => 'ZFTools\\Controller\\Diagnostics', 'action' => 'run'));
$event->setRouteMatch($this->routeMatch);
$this->controller = new DiagnosticsController();
$this->controller->setServiceLocator($this->sm);
$this->controller->setEvent($event);
}
示例3: testHasAlias
/**
* @covers Zend\ServiceManager\ServiceManager::hasAlias
*/
public function testHasAlias()
{
$this->assertFalse($this->serviceManager->hasAlias('foo'));
$this->serviceManager->setService('bar', 'baz');
$this->serviceManager->setAlias('foo', 'bar');
$this->assertTrue($this->serviceManager->hasAlias('foo'));
}
示例4: getRouteNotFoundStrategy
/**
* Instantiates and configures the "route not found", or 404, strategy
*
* @return RouteNotFoundStrategy
*/
public function getRouteNotFoundStrategy()
{
if ($this->routeNotFoundStrategy) {
return $this->routeNotFoundStrategy;
}
$this->routeNotFoundStrategy = new RouteNotFoundStrategy();
$displayExceptions = false;
$displayNotFoundReason = false;
$notFoundTemplate = '404';
if (isset($this->config['display_exceptions'])) {
$displayExceptions = $this->config['display_exceptions'];
}
if (isset($this->config['display_not_found_reason'])) {
$displayNotFoundReason = $this->config['display_not_found_reason'];
}
if (isset($this->config['not_found_template'])) {
$notFoundTemplate = $this->config['not_found_template'];
}
$this->routeNotFoundStrategy->setDisplayExceptions($displayExceptions);
$this->routeNotFoundStrategy->setDisplayNotFoundReason($displayNotFoundReason);
$this->routeNotFoundStrategy->setNotFoundTemplate($notFoundTemplate);
$this->services->setService('RouteNotFoundStrategy', $this->routeNotFoundStrategy);
$this->services->setAlias('Zend\\Mvc\\View\\RouteNotFoundStrategy', 'RouteNotFoundStrategy');
$this->services->setAlias('Zend\\Mvc\\View\\Http\\RouteNotFoundStrategy', 'RouteNotFoundStrategy');
$this->services->setAlias('404Strategy', 'RouteNotFoundStrategy');
return $this->routeNotFoundStrategy;
}
示例5: 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'));
}
示例6: createServiceManager
protected function createServiceManager(array $config)
{
$serviceManager = new ServiceManager(new Config($config));
$serviceManager->setService('Configuration', $config);
$serviceManager->setAlias('Config', 'Configuration');
return $serviceManager;
}
示例7: testCreateService
/**
* Test get SessionManager
*
* @expectedException PHPUnit_Framework_Error_Warning
*/
public function testCreateService()
{
$serviceManager = new ServiceManager();
$serviceFactory = new SessionManagerFactory();
$serviceManager->setAlias('Configuration', 'Config')->setService('Config', array())->setService('Zend\\Session\\Storage\\StorageInterface', new ArrayStorage());
$serviceFactory->createService($serviceManager);
}
示例8: initServiceManager
/**
* @param array $applicationConfig
* @return ServiceManager
*/
protected function initServiceManager(array $applicationConfig)
{
$smConfig = new Config(isset($applicationConfig['service_manager']) ? $applicationConfig['service_manager'] : []);
$serviceManager = new ServiceManager($smConfig);
$serviceManager->setService('Config', $applicationConfig);
$serviceManager->setAlias('Configuration', 'Config');
return $serviceManager;
}
示例9: testCanGetAliasedServicesFromPeeringServiceManagers
/**
* @covers Zend\ServiceManager\ServiceManager::setAlias
* @covers Zend\ServiceManager\ServiceManager::get
* @covers Zend\ServiceManager\ServiceManager::retrieveFromPeeringManager
*/
public function testCanGetAliasedServicesFromPeeringServiceManagers()
{
$service = new \stdClass();
$peeringSm = new ServiceManager();
$peeringSm->setService('actual-service-name', $service);
$this->serviceManager->addPeeringServiceManager($peeringSm);
$this->serviceManager->setAlias('alias-name', 'actual-service-name');
$this->assertSame($service, $this->serviceManager->get('alias-name'));
}
示例10: getZendMonitorExceptionStrategy
/**
* Instantiates and configures the Zend Monitor Exception strategy
* @return \Zend\Mvc\View\Http\ZendMonitorExceptionStrategy
*/
public function getZendMonitorExceptionStrategy()
{
if ($this->zendMonitorExceptionStrategy) {
return $this->zendMonitorExceptionStrategy;
}
$this->zendMonitorExceptionStrategy = new ZendMonitorExceptionStrategy();
$this->services->setService('zendMonitorExceptionStrategy', $this->zendMonitorExceptionStrategy);
$this->services->setAlias('Zend\\Mvc\\View\\Http\\ZendMonitorExceptionStrategy', 'ZendMonitorExceptionStrategy');
return $this->zendMonitorExceptionStrategy;
}
示例11: 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);
}
示例12: createServiceManager
public function createServiceManager($config)
{
$serviceManager = new ServiceManager();
$serviceManager->setService('AsseticAssetManager', $this->assetManager);
$serviceManager->setService('router', $this->router);
$serviceManager->setService('Configuration', $config);
$serviceManager->setAlias('Config', 'Configuration');
$serviceManager->setService('AssetManifest', $this->createAssetManifest($config));
return $serviceManager;
}
示例13: testAssignAliasWithExistingServiceName
/**
* @expectedException Zend\ServiceManager\Exception\InvalidServiceNameException
*/
public function testAssignAliasWithExistingServiceName()
{
$this->serviceManager->setFactory('foo', 'ZendTest\\ServiceManager\\TestAsset\\FooFactory');
$this->serviceManager->setFactory('bar', function ($sm) {
return new Bar(array('a'));
});
$this->serviceManager->setAllowOverride(false);
// should throw an exception because 'foo' already exists in the service manager
$this->serviceManager->setAlias('foo', 'bar');
}
示例14: configureServiceManager
/**
* Configure the provided service manager instance with the configuration
* in this class.
*
* @param ServiceManager $serviceManager
* @return ServiceManager
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
foreach ($this->factories as $name => $factory) {
$serviceManager->setFactory($name, $factory);
}
foreach ($this->aliases as $alias => $target) {
$serviceManager->setAlias($alias, $target);
}
return $serviceManager;
}
示例15: testCreateService
/**
* Test get SessionManager
*/
public function testCreateService()
{
$serviceManager = new ServiceManager();
$serviceFactory = new SessionConfigFactory();
$serviceManager->setAlias('Zork\\Db\\SiteInfo', 'SiteInfo')->setAlias('Configuration', 'Config')->setService('Config', array('session_config' => array()))->setService('SiteInfo', new SiteInfo(array('domain' => 'example.com')));
/* @var $service \Zend\Session\Config\ConfigInterface */
$service = $serviceFactory->createService($serviceManager);
$this->assertInstanceOf('Zend\\Session\\Config\\ConfigInterface', $service);
$this->assertEquals('.example.com', $service->getCookieDomain());
}