本文整理汇总了PHP中Zend\Mvc\MvcEvent::setControllerClass方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::setControllerClass方法的具体用法?PHP MvcEvent::setControllerClass怎么用?PHP MvcEvent::setControllerClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mvc\MvcEvent
的用法示例。
在下文中一共展示了MvcEvent::setControllerClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testShouldCache
/**
* @param array $controllers
* @param string $requestedController
* @param boolean $expectedResult
* @dataProvider shouldCacheProvider
*/
public function testShouldCache($controllers, $requestedController, $expectedResult)
{
$this->strategy->setControllers($controllers);
$mvcEvent = new MvcEvent();
$mvcEvent->setControllerClass($requestedController);
$mvcEvent->setRouteMatch(new RouteMatch(array('controller' => $requestedController)));
$this->assertEquals($expectedResult, $this->strategy->shouldCache($mvcEvent));
}
示例2: onRoute
/**
* Global Route /module/controller/action
* @param MvcEvent $e
*/
public function onRoute(MvcEvent $e)
{
$matches = $e->getRouteMatch();
$module = $matches->getParam('module');
$controller = $matches->getParam('controller');
if ($module && $controller && strpos($controller, '\\') === false) {
$matches->setParam(self::ORIGINAL_CONTROLLER, $controller);
$controllerLoader = $e->getApplication()->getServiceManager()->get('ControllerManager');
$ctrlClass = $this->convertName($module) . '\\Controller\\';
$ctrlClass .= $this->convertName($controller);
$controller = $ctrlClass;
$matches->setParam('controller', $controller);
$ctrlClass .= 'Controller';
if (!$controllerLoader->has($controller) && class_exists($ctrlClass)) {
$controllerLoader->setInvokableClass($controller, $ctrlClass);
$e->setController($controller);
$e->setControllerClass($ctrlClass);
}
}
}
示例3: test404ResponsePrepares404ViewModelWithControllerWhenAllowed
public function test404ResponsePrepares404ViewModelWithControllerWhenAllowed()
{
$response = new Response();
$event = new MvcEvent();
$controller = 'some-or-other';
$controllerClass = 'Some\\Controller\\OrOtherController';
$event->setController($controller);
$event->setControllerClass($controllerClass);
foreach (array('setDisplayNotFoundReason', 'setDisplayExceptions') as $method) {
foreach (array(true, false) as $allow) {
$this->strategy->{$method}($allow);
$response->setStatusCode(404);
$event->setResult(null);
$event->setResponse($response);
$this->strategy->prepareNotFoundViewModel($event);
$model = $event->getResult();
$this->assertInstanceOf('Zend\\View\\Model\\ModelInterface', $model);
$variables = $model->getVariables();
if ($allow) {
$this->assertTrue(isset($variables['controller']));
$this->assertEquals($controller, $variables['controller']);
$this->assertTrue(isset($variables['controller_class']));
$this->assertEquals($controllerClass, $variables['controller_class']);
} else {
$this->assertFalse(isset($variables['controller']));
$this->assertFalse(isset($variables['controller_class']));
}
}
}
}
示例4: marshalMiddlewareNotCallable
/**
* Marshal a middleware not callable exception event
*
* @param string $type
* @param string $middlewareName
* @param MvcEvent $event
* @param Application $application
* @param \Exception $exception
* @return mixed
*/
protected function marshalMiddlewareNotCallable($type, $middlewareName, MvcEvent $event, Application $application, \Exception $exception = null)
{
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$event->setError($type);
$event->setController($middlewareName);
$event->setControllerClass('Middleware not callable: ' . $middlewareName);
if ($exception !== null) {
$event->setParam('exception', $exception);
}
$events = $application->getEventManager();
$results = $events->triggerEvent($event);
$return = $results->last();
if (!$return) {
$return = $event->getResult();
}
return $return;
}
示例5: marshalControllerNotFoundEvent
/**
* Marshal a controller not found exception event
*
* @param string $type
* @param string $controllerName
* @param MvcEvent $event
* @param Application $application
* @param \Throwable|\Exception $exception
* @return mixed
*/
protected function marshalControllerNotFoundEvent($type, $controllerName, MvcEvent $event, Application $application, $exception = null)
{
$event->setName(MvcEvent::EVENT_DISPATCH_ERROR);
$event->setError($type);
$event->setController($controllerName);
$event->setControllerClass('invalid controller class or alias: ' . $controllerName);
if ($exception !== null) {
$event->setParam('exception', $exception);
}
$events = $application->getEventManager();
$results = $events->triggerEvent($event);
$return = $results->last();
if (!$return) {
$return = $event->getResult();
}
return $return;
}