当前位置: 首页>>代码示例>>PHP>>正文


PHP MvcEvent::getControllerClass方法代码示例

本文整理汇总了PHP中Zend\Mvc\MvcEvent::getControllerClass方法的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent::getControllerClass方法的具体用法?PHP MvcEvent::getControllerClass怎么用?PHP MvcEvent::getControllerClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mvc\MvcEvent的用法示例。


在下文中一共展示了MvcEvent::getControllerClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onError

 public function onError(MvcEvent $event)
 {
     // if error has been removed
     if ($event->isError() == false) {
         return;
     }
     $locator = $event->getApplication()->getServiceManager();
     /* @var $errorService \BitWeb\ErrorReporting\Service\ErrorService */
     $errorService = $locator->get('BitWeb\\ErrorReporting\\Service\\ErrorService');
     $exception = $event->getParam('exception');
     $error = $event->getError();
     $stopPropagation = false;
     if ($exception instanceof \Exception) {
         $errorService->errors[] = $exception;
         if ($exception instanceof \PDOException) {
             $stopPropagation = true;
         }
     } elseif ($error != null) {
         $errorService->errors[] = new RouterNoMatchException(sprintf('%1$s, %2$s', $error, $event->getControllerClass()));
     }
     if ($stopPropagation) {
         $this->onFinishAfterPostDispatch($event);
     }
 }
开发者ID:bitweb,项目名称:zf2-error-reporting-module,代码行数:24,代码来源:Module.php

示例2: injectController

 /**
  * Inject the controller and controller class into the model
  *
  * If either $displayExceptions or $displayNotFoundReason are enabled,
  * injects the controllerClass from the MvcEvent. It checks to see if a
  * controller is present in the MvcEvent, and, if not, grabs it from
  * the route match if present; if a controller is found, it injects it into
  * the model.
  *
  * @param  ViewModel $model
  * @param  MvcEvent $e
  * @return void
  */
 protected function injectController($model, $e)
 {
     if (!$this->displayExceptions() && !$this->displayNotFoundReason()) {
         return;
     }
     $controller = $e->getController();
     if (empty($controller)) {
         $routeMatch = $e->getRouteMatch();
         if (empty($routeMatch)) {
             return;
         }
         $controller = $routeMatch->getParam('controller', false);
         if (!$controller) {
             return;
         }
     }
     $controllerClass = $e->getControllerClass();
     $model->setVariable('controller', $controller);
     $model->setVariable('controller_class', $controllerClass);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:33,代码来源:RouteNotFoundStrategy.php

示例3: detectError

 public function detectError(MvcEvent $event)
 {
     $result = $event->getResult();
     if ($result instanceof ResponseInterface) {
         // Already have a response as the result
         return;
     }
     $error = $event->getError();
     $ex = $event->getParam('exception');
     switch ($error) {
         case Application::ERROR_CONTROLLER_NOT_FOUND:
             $message = ucfirst($event->getControllerClass());
             $ex = new RdnException\RuntimeException($message, 500, $ex);
             break;
         case Application::ERROR_CONTROLLER_INVALID:
             $message = $event->getController() . ' is not dispatchable';
             $ex = new RdnException\RuntimeException($message, 500, $ex);
             break;
         case Application::ERROR_ROUTER_NO_MATCH:
             $message = 'Request did not match any routes.';
             $ex = new RdnException\NotFoundException($message, 404, $ex);
             break;
     }
     if (isset($message)) {
         if ($ex->getCode() == 500) {
             $event->setError(Application::ERROR_EXCEPTION);
         }
         $event->setParam('exception', $ex);
     }
 }
开发者ID:radnan,项目名称:rdn-exception,代码行数:30,代码来源:ExceptionStrategy.php

示例4: format

 /**
  * @param \Zend\Mvc\MvcEvent $object
  * @param array $options
  *
  * @return array
  */
 public function format($object, array $options)
 {
     $data['route']['name'] = $object->getRouteMatch()->getMatchedRouteName();
     $data['route']['params'] = $object->getRouteMatch()->getParams();
     $parts = explode('/', $data['route']['name']);
     $route = $object->getRouter();
     $config = $object->getApplication()->getServiceManager()->get('config');
     $config = isset($config['router']['routes']) ? $config['router']['routes'] : [];
     while ($part = array_shift($parts)) {
         $route->hasRoute($part) and $route = $route->getRoute($part);
         isset($config[$part]) and $config = $config[$part];
     }
     $data['route']['class'] = get_class($route);
     $data['route']['assembled'] = $route->getAssembledParams();
     $data['event']['error'] = $object->getError();
     $data['event']['name'] = $object->getName();
     $controllers = [];
     $definitions = [];
     $title = '404 Error';
     $subtitle = 'Unknown Error';
     $context = null;
     $manager = $object->getApplication()->getServiceManager()->get('ControllerLoader');
     switch ($object->getError()) {
         case Application::ERROR_CONTROLLER_NOT_FOUND:
             $definitions = $config;
             $title = $object->getControllerClass();
             $subtitle = 'The requested controller cannot be found';
             $controllers = $manager->getCanonicalNames();
             array_pop($controllers);
             // because the Sm add the wrong into the list
             break;
         case Application::ERROR_CONTROLLER_INVALID:
             $title = $object->getControllerClass();
             $subtitle = $object->getParam('exception')->getMessage();
             break;
         case Application::ERROR_CONTROLLER_CANNOT_DISPATCH:
             $context = $this->getControllerContext($manager, $data['route']['params']);
             $subtitle = 'The controller cannot dispatch the request';
             $title = $data['route']['params']['controller'];
             break;
     }
     $data['title'] = $title;
     $data['subtitle'] = $subtitle;
     $data['route']['definition'] = $definitions;
     $data['controller']['names'] = $controllers;
     $data['controller']['context'] = $context;
     return $data;
 }
开发者ID:ronan-gloo,项目名称:zf2-error-manager,代码行数:54,代码来源:ControllerFormatter.php

示例5: onBootstrap

 public function onBootstrap(MvcEvent $event)
 {
     $eventManager = $event->getApplication()->getEventManager();
     $oauth2Closure = $event->getApplication()->getServiceManager()->get(\ZF\OAuth2\Service\OAuth2Server::class);
     $logger = $event->getApplication()->getServiceManager()->get('logger');
     $eventManager->attach(MvcAuthEvent::EVENT_AUTHENTICATION_POST, function (MvcAuthEvent $event) use($oauth2Closure) {
         // Manipulating Identity Data
         $identity = $event->getIdentity();
         if (!!$identity) {
             if ($identity instanceof AuthenticatedIdentity) {
                 $userData = $oauth2Closure()->getStorage('user_credentials')->getUser($identity->getName());
                 if (is_array($identity->getAuthenticationIdentity())) {
                     $userData = array_merge($userData, $identity->getAuthenticationIdentity());
                 }
                 $identity = new AuthenticatedIdentity($userData);
                 $event->setIdentity($identity);
             }
             //MvcEvent did not understand when manipulated MvcAuthEvent identity
             $event->getMvcEvent()->setParam('ZF\\MvcAuth\\Identity', $identity);
         }
         return $event;
     }, 900);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) use($logger) {
         $problem = null;
         if ($event->isError()) {
             $exception = $event->getParam("exception");
             // There are some other errors like that :
             // "error-controller-cannot-dispatch",
             // "error-controller-invalid",
             // "error-controller-not-found",
             // "error-router-no-match",
             if ($event->getError() === 'error-controller-not-found') {
                 $problem = new ApiProblem(404, "Endpoint controller not found!");
             } elseif ($event->getError() === 'error-router-no-match') {
                 $problem = new ApiProblem(404, "Not found!");
             } elseif ($exception instanceof \Exception) {
                 $className = explode('\\', get_class($exception));
                 $problem = new ApiProblem($exception->getCode(), end($className) . ' error.');
                 $logger->err($exception->getMessage(), array('controller' => $event->getControllerClass()));
             }
         } else {
             $problem = new ApiProblem(500, "Unknown Error!");
         }
         $response = new ApiProblemResponse($problem);
         $event->stopPropagation();
         return $response;
     }, 9000);
 }
开发者ID:biberlabs,项目名称:zf2-boilerplate,代码行数:50,代码来源:Module.php


注:本文中的Zend\Mvc\MvcEvent::getControllerClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。