本文整理汇总了PHP中Zend\Mvc\Controller\ControllerManager::has方法的典型用法代码示例。如果您正苦于以下问题:PHP ControllerManager::has方法的具体用法?PHP ControllerManager::has怎么用?PHP ControllerManager::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\Controller\ControllerManager
的用法示例。
在下文中一共展示了ControllerManager::has方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mockConfiguration
/**
* @param \Zend\Mvc\Controller\ControllerManager $controllerManager
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
* @param array $routeParams
*/
protected function mockConfiguration($controllerManager, $serviceLocator, $routeParams = array('action' => 'list'))
{
$prophet = new Prophet();
$controllerKey = 'Phpro\\SmartCrud\\Controller\\CrudController';
$serviceKey = 'Phpro\\SmartCrud\\Service\\AbstractSmartService';
$viewBuilderKey = 'Phpro\\SmartCrud\\View\\Model\\ViewModelBuilder';
$controllerManager->getServiceLocator()->willReturn($serviceLocator);
// Mock config
$serviceLocator->has('Config')->willReturn(true);
$serviceLocator->get('Config')->willReturn(array(AbstractCrudControllerFactory::FACTORY_NAMESPACE => array('custom-controller' => array(AbstractCrudControllerFactory::CONFIG_CONTROLLER => $controllerKey, AbstractCrudControllerFactory::CONFIG_IDENTIFIER => 'id', AbstractCrudControllerFactory::CONFIG_SMART_SERVICE => $serviceKey), 'fault-controller' => array(AbstractCrudControllerFactory::CONFIG_CONTROLLER => 'invalid-controller'), 'fault-service' => array(AbstractCrudControllerFactory::CONFIG_SMART_SERVICE => 'invalid-service'))));
// Mock controller
$controller = $prophet->prophesize('\\Phpro\\SmartCrud\\Controller\\CrudController');
$controllerManager->has($controllerKey)->willReturn(true);
$controllerManager->get($controllerKey)->willReturn($controller);
$controllerManager->has('invalid-controller')->willReturn(false);
// Mock route
$this->mockRouteMatch($serviceLocator, $routeParams);
// Mock service
$serviceKey = $serviceKey . '::' . $routeParams['action'];
$service = $prophet->prophesize('\\Phpro\\SmartCrud\\Service\\AbstractSmartService');
$serviceLocator->has($serviceKey)->willReturn(true);
$serviceLocator->get($serviceKey)->willReturn($service);
$serviceLocator->has('invalid-service::' . $routeParams['action'])->willReturn(false);
$viewBuilder = $prophet->prophesize('\\Phpro\\SmartCrud\\View\\Model\\ViewModelBuilder');
$serviceLocator->has($viewBuilderKey)->willReturn(true);
$serviceLocator->get($viewBuilderKey)->willReturn($viewBuilder);
$this->setServiceLocator($serviceLocator);
}
示例2: toUrl
/**
* Redirect with Handling against url.
*
* @param string $url
*
* @return Response
*/
public function toUrl($url)
{
$allow_not_routed_url = isset($this->config['allow_not_routed_url']) ? $this->config['allow_not_routed_url'] : false;
$exclude_urls = isset($this->config['options']['exclude_urls']) ? $this->config['options']['exclude_urls'] : [];
$exclude_hosts = isset($this->config['options']['exclude_hosts']) ? $this->config['options']['exclude_hosts'] : [];
$uriTargetHost = (new Uri($url))->getHost();
if (true === $allow_not_routed_url || in_array($url, $exclude_urls) || in_array($uriTargetHost, $exclude_hosts)) {
return parent::toUrl($url);
}
$controller = $this->getController();
$request = $controller->getRequest();
$current_uri = $request->getRequestUri();
$request->setUri($url);
$uriTarget = (new Uri($url))->__toString();
if ($current_uri === $uriTarget) {
$this->getEventManager()->trigger('redirect-same-url');
return;
}
$mvcEvent = $this->getEvent();
$routeMatch = $mvcEvent->getRouteMatch();
$currentRouteMatchName = $routeMatch->getMatchedRouteName();
$router = $mvcEvent->getRouter();
$uriCurrentHost = (new Uri($router->getRequestUri()))->getHost();
if (($routeToBeMatched = $router->match($request)) && ($uriTargetHost === null || $uriCurrentHost === $uriTargetHost) && (($routeToBeMatchedRouteName = $routeToBeMatched->getMatchedRouteName()) !== $currentRouteMatchName && ($this->manager->has($routeToBeMatched->getParam('controller')) || $routeToBeMatched->getParam('middleware') !== false) || $routeToBeMatched->getParam('action') != $routeMatch->getParam('action') || $routeToBeMatchedRouteName === $currentRouteMatchName)) {
return parent::toUrl($url);
}
$default_url = isset($this->config['default_url']) ? $this->config['default_url'] : '/';
return parent::toUrl($default_url);
}
示例3: testWillInstantiateControllersFromDiAbstractFactoryWhenWhitelisted
public function testWillInstantiateControllersFromDiAbstractFactoryWhenWhitelisted()
{
$config = new ArrayObject(array('di' => array('instance' => array('alias' => array('my-controller' => 'stdClass')), 'allowed_controllers' => array('my-controller'))));
$this->services->setAllowOverride(true);
$this->services->setService('Config', $config);
$this->loader = $this->services->get('ControllerLoader');
$this->assertTrue($this->loader->has('my-controller'));
// invalid controller exception (because we're getting an \stdClass after all)
$this->setExpectedException('Zend\\Mvc\\Exception\\InvalidControllerException');
$this->loader->get('my-controller');
}
示例4: testCreation
public function testCreation()
{
$moduleManagerMock = $this->getMockBuilder('Zend\\ModuleManager\\ModuleManager')->disableOriginalConstructor()->getMock();
$this->serviceManager->setService('ModuleManager', $moduleManagerMock);
$this->assertTrue($this->controllerManager->has('Modules\\Controller\\Console\\List'));
$controller = $this->controllerManager->get('Modules\\Controller\\Console\\List');
$this->assertInstanceOf('Modules\\Controller\\Console\\ListController', $controller);
$this->assertAttributeInstanceOf('ComposerLockParser\\ComposerInfo', 'composerInfo', $controller);
$this->assertAttributeEquals($moduleManagerMock, 'moduleManager', $controller);
$this->assertAttributeInstanceOf('Zend\\View\\Renderer\\PhpRenderer', 'renderer', $controller);
$this->assertAttributeInstanceOf('Modules\\ViewModel\\Console\\ListViewModel', 'viewModel', $controller);
}
示例5: injectControllerClass
/**
* Inject the class name of the controller, if it can be resolved.
*
* @param RpcServiceEntity $service
*/
protected function injectControllerClass(RpcServiceEntity $service)
{
$controllerServiceName = $service->controllerServiceName;
if (!$this->controllerManager->has($controllerServiceName)) {
return;
}
$controller = $this->controllerManager->get($controllerServiceName);
$service->exchangeArray(['controller_class' => get_class($controller)]);
}
示例6: has
/**
* Override: do not use peering service managers
*
* @param string|array $name
* @param bool $checkAbstractFactories
* @param bool $usePeeringServiceManagers
* @return bool
* @SuppressWarnings(PHPMD.LongVariable)
*/
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = false)
{
if (is_string($name) && $this->container->has($name)) {
return true;
} elseif (parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers)) {
return true;
}
return false;
}
示例7: injectControllerClass
/**
* Inject the class name of the controller, if it can be resolved.
*
* @param DoctrineRpcServiceEntity $service
*/
protected function injectControllerClass(DoctrineRpcServiceEntity $service)
{
$controllerServiceName = $service->controllerServiceName;
if (!$this->controllerManager->has($controllerServiceName)) {
// @codeCoverageIgnoreStart
return;
// @codeCoverageIgnoreEnd
}
$controller = $this->controllerManager->get($controllerServiceName);
$service->exchangeArray(array('controller_class' => get_class($controller)));
}