本文整理匯總了PHP中Zend\Mvc\Controller\ControllerManager::get方法的典型用法代碼示例。如果您正苦於以下問題:PHP ControllerManager::get方法的具體用法?PHP ControllerManager::get怎麽用?PHP ControllerManager::get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Mvc\Controller\ControllerManager
的用法示例。
在下文中一共展示了ControllerManager::get方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: dispatch
/**
* Dispatch another controller
*
* @param string $name Controller name; either a class name or an alias used in the controller manager
* @param null|array $params Parameters with which to seed a custom RouteMatch object for the new controller
* @return mixed
* @throws Exception\DomainException if composed controller does not define InjectApplicationEventInterface
* or Locator aware; or if the discovered controller is not dispatchable
*/
public function dispatch($name, array $params = null)
{
$event = clone $this->getEvent();
$controller = $this->controllers->get($name);
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($event);
}
// Allow passing parameters to seed the RouteMatch with & copy matched route name
if ($params !== null) {
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName());
$event->setRouteMatch($routeMatch);
}
if ($this->numNestedForwards > $this->maxNestedForwards) {
throw new Exception\DomainException("Circular forwarding detected: greater than {$this->maxNestedForwards} nested forwards");
}
$this->numNestedForwards++;
// Detach listeners that may cause problems during dispatch:
$sharedEvents = $event->getApplication()->getEventManager()->getSharedManager();
$listeners = $this->detachProblemListeners($sharedEvents);
$return = $controller->dispatch($event->getRequest(), $event->getResponse());
// If we detached any listeners, reattach them now:
$this->reattachProblemListeners($sharedEvents, $listeners);
$this->numNestedForwards--;
return $return;
}
示例3: dispatch
/**
* Dispatch another controller
*
* @param string $name Controller name; either a class name or an alias used in the controller manager
* @param null|array $params Parameters with which to seed a custom RouteMatch object for the new controller
* @return mixed
* @throws Exception\DomainException if composed controller does not define InjectApplicationEventInterface
* or Locator aware; or if the discovered controller is not dispatchable
*/
public function dispatch($name, array $params = null)
{
$event = clone $this->getEvent();
if (is_array($params) && isset($params[ModuleRouteListener::MODULE_NAMESPACE])) {
$module = $params[ModuleRouteListener::MODULE_NAMESPACE];
if (strpos($name, $module) !== 0) {
if (!isset($params[ModuleRouteListener::ORIGINAL_CONTROLLER])) {
$params[ModuleRouteListener::ORIGINAL_CONTROLLER] = $name;
}
$name = $module . '\\' . str_replace(' ', '', ucwords(str_replace('-', ' ', $name)));
}
}
$controller = $this->controllers->get($name);
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($event);
}
// Allow passing parameters to seed the RouteMatch with & copy matched route name
if ($params !== null) {
$routeMatch = new RouteMatch($params);
$routeMatch->setMatchedRouteName($event->getRouteMatch()->getMatchedRouteName());
$event->setRouteMatch($routeMatch);
}
if ($this->numNestedForwards > $this->maxNestedForwards) {
throw new Exception\DomainException("Circular forwarding detected: greater than {$this->maxNestedForwards} nested forwards");
}
$this->numNestedForwards++;
// Detach listeners that may cause problems during dispatch:
$sharedEvents = $event->getApplication()->getEventManager()->getSharedManager();
$listeners = $this->detachProblemListeners($sharedEvents);
$return = $controller->dispatch($event->getRequest(), $event->getResponse());
// If we detached any listeners, reattach them now:
$this->reattachProblemListeners($sharedEvents, $listeners);
$this->numNestedForwards--;
return $return;
}
示例4: 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);
}
示例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: 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)));
}
示例7: testWillFetchDiDependenciesFromControllerLoaderServiceManager
public function testWillFetchDiDependenciesFromControllerLoaderServiceManager()
{
$controllerName = __NAMESPACE__ . '\\TestAsset\\ControllerWithDependencies';
// rewriting since controller loader does not have the correct config, but is already fetched
$config = new ArrayObject(array('di' => array('instance' => array($controllerName => array('parameters' => array('injected' => 'stdClass'))), 'allowed_controllers' => array($controllerName))));
$this->services->setAllowOverride(true);
$this->services->setService('Config', $config);
$this->loader = $this->services->get('ControllerLoader');
$testService = new \stdClass();
$this->services->setService('stdClass', $testService);
// invalid controller exception (because we're not getting a \Zend\Stdlib\DispatchableInterface after all)
$controller = $this->loader->get($controllerName);
$this->assertSame($testService, $controller->injectedValue);
}
示例8: createPath
/**
* @param $controllerName
* @param array $controller
*/
private function createPath($controllerName, array $controller)
{
foreach ($controller as $action => $template) {
try {
/** @var AbstractActionController $controllerClass */
$controllerClass = $this->controllerManager->get($controllerName);
$controllerClass->setEvent($this->application->getMvcEvent());
$viewModel = $controllerClass->{$action}();
} catch (\Exception $e) {
$viewModel = null;
}
$this->createPathFromViewModel($viewModel, $controllerName, $action);
}
}
示例9: get
/**
* Retrieve a service from the manager by name
*
* Allows passing an array of options to use when creating the instance.
* createFromInvokable() will use these and pass them to the instance
* constructor if not null and a non-empty array.
*
* @param string $name
* @param array $options
* @param bool $usePeeringServiceManagers
*
* @return object
*
* @throws Exception\ServiceNotFoundException
* @throws Exception\ServiceNotCreatedException
* @throws Exception\RuntimeException
* @SuppressWarnings(PHPMD.LongVariable)
*/
public function get($name, $options = array(), $usePeeringServiceManagers = true)
{
$controller = null;
if ($this->container->has($name)) {
$controller = $this->container->get($name);
$this->initialize($controller);
} elseif (parent::has($name, true, $usePeeringServiceManagers)) {
$controller = parent::get($name, $options, $usePeeringServiceManagers);
}
if (!$controller) {
throw new Exception\ServiceNotFoundException("Unable to locate service '{$name}'");
} elseif (!$controller instanceof DispatchableInterface) {
throw new Exception\RuntimeException("Service '{$name}' is not a Controller.");
}
return $controller;
}
示例10: formFactory
/**
*
* @param ControllerManager $sl
* @param Contentinum\Options\PageOptions $pageOptions
* @param ContentinumComponents\Mapper\Worker $worker
*/
protected function formFactory($sl, $pageOptions, $worker)
{
if (false !== ($formName = $pageOptions->getApp('form'))) {
if (false !== ($targetEntities = $pageOptions->getApp('targetentities'))) {
if (is_array($targetEntities) && !empty($targetEntities)) {
foreach ($targetEntities as $key => $tEntity) {
$worker->addTargetEntities($key, $tEntity);
}
}
}
$formFactory = new $formName($worker);
$decorators = $sl->get($pageOptions->getApp('formdecorators'));
$decorators = $decorators->default->toArray();
if (false != ($formAttribs = $pageOptions->getApp('formattributes'))) {
$decorators['deco-form']['form-attributtes'] = array_merge($decorators['deco-form']['form-attributtes'], $formAttribs);
}
$formFactory->setDecorators($decorators);
$formFactory->setServiceLocator($sl);
return $formFactory;
} else {
return false;
}
}