onDispatch() public method

Handle the request
public onDispatch ( MvcEvent $e ) : mixed
$e Zend\Mvc\MvcEvent
return mixed
 public function onDispatch(MvcEvent $e)
 {
     $this->range = null;
     $this->model = $this->acceptableViewModelSelector($this->options->getAcceptCriteria());
     $this->options->getDocumentManager()->getEventManager()->addEventSubscriber($this);
     return parent::onDispatch($e);
 }
 /**
  * Handle the request
  *
  * @param  MvcEvent $e
  * @return mixed
  */
 public function onDispatch(MvcEvent $e)
 {
     try {
         parent::onDispatch($e);
     } catch (\Exception $e) {
         return $this->getResponse()->setStatusCode(500)->setContent($e->__toString());
     }
 }
 public function onDispatch(MvcEvent $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $this->config = $sm->get('Config');
     $this->session = new Container($this->config['session']['container_name']);
     // Pass it up to the parent
     parent::onDispatch($e);
 }
 /**
  * ZF требует, чтобы клиент передавал id с именем $identifierName в GET-запросе либо чтобы
  * в маршруте распознавался id также с именем $identifierName.
  * Маршрут для каждого запроса (с разным именем id) писать накладно.
  * Переделывать чтобы клиент передавал в GET-запросе имя id не хочется.
  * Поэтому тут сделано подстановка в запрос id с именем $identifierName.
  */
 public function onDispatch(MvcEvent $e)
 {
     if ($this->getIdentifierName() != "id") {
         $routeMatch = $e->getRouteMatch();
         $id = $routeMatch->getParam("id", false);
         $routeMatch->setParam($this->getIdentifierName(), $id);
     }
     return parent::onDispatch($e);
 }
 public function onDispatch(MvcEvent $e)
 {
     $response = parent::onDispatch($e);
     $request = $e->getRequest();
     $method = strtolower($request->getMethod());
     if ($method === "options") {
         $e->setResult($this->options());
         return $e;
     }
     return $response;
 }
Beispiel #6
0
 /**
  * Handle dispatch event
  *
  * Does several "pre-flight" checks:
  * - Raises an exception if no resource is composed.
  * - Raises an exception if no route is composed.
  * - Returns a 405 response if the current HTTP request method is not in
  *   $options
  *
  * @param MvcEvent $e
  * @return mixed|ProblemResponse
  * @throws \Parrot\API\Resource\Exception\ResourceNotImplementedException
  */
 public function onDispatch(MvcEvent $e)
 {
     if (!$this->getResource() && !$this->locateResource($e->getRouteMatch()->getParam('resource'))) {
         throw new ResourceNotImplementedException();
     }
     // Check for an API-Problem in the event
     $return = $e->getParam('api-problem', false);
     // If no API-Problem, dispatch the parent event
     if (!$return) {
         $return = parent::onDispatch($e);
     }
     if (!$return instanceof Problem) {
         return $return;
     }
     if ($return instanceof Problem) {
         return new ProblemResponse($return);
     }
 }
 /**
  * Override this function to ensure that all values returned is always a JsonModel
  * @param MvcEvent $e
  * @return JsonModel
  * */
 public function onDispatch(MvcEvent $e)
 {
     try {
         $return = parent::onDispatch($e);
     } catch (\Exception $ex) {
         $previous = $ex->getPrevious();
         if ($previous) {
             $ex = $previous;
         }
         return $this->responseError(500, $ex->getMessage());
     }
     if (is_array($return) || $return instanceof \Iterator || $return instanceof \ArrayObject) {
         // encapsulate arrays, Iterator, or ArrayObject in a JsonModel
         $return = new JsonModel($return);
         $e->setResult($return);
     } else {
         if (!$return instanceof JsonModel && !$return instanceof Response) {
             // unrecognized return type, return output as is
             return $this->responseError(500, 'Unknown return format');
         }
     }
     return $return;
 }
 public function onDispatch(MvcEvent $e)
 {
     //$this->config($e);
     $this->controller = $e->getTarget();
     parent::onDispatch($e);
 }
Beispiel #9
0
 /**
  * Validate the API request and set global options.
  *
  * @param MvcEvent $event
  */
 public function onDispatch(MvcEvent $event)
 {
     $request = $this->getRequest();
     // Set pretty print.
     $prettyPrint = $request->getQuery('pretty_print');
     if (null !== $prettyPrint) {
         $this->setViewOption('pretty_print', true);
     }
     // Set the JSONP callback.
     $callback = $request->getQuery('callback');
     if (null !== $callback) {
         $this->setViewOption('callback', $callback);
     }
     try {
         // Finish dispatching the request.
         $this->checkContentType($request);
         parent::onDispatch($event);
     } catch (\Exception $e) {
         $this->getServiceLocator()->get('Omeka\\Logger')->err((string) $e);
         return $this->getErrorResult($event, $e);
     }
 }
 public function onDispatch(MvcEvent $e)
 {
     $this->model = $this->acceptableViewModelSelector($this->options->getAcceptCriteria());
     return parent::onDispatch($e);
 }
 public function onDispatch(MvcEvent $event)
 {
     $this->model = $this->acceptableViewModelSelector($this->acceptCriteria);
     return parent::onDispatch($event);
 }
Beispiel #12
0
    /**
     * Handle the dispatch event
     *
     * Does several "pre-flight" checks:
     * - Raises an exception if no resource is composed.
     * - Raises an exception if no route is composed.
     * - Returns a 405 response if the current HTTP request method is not in
     *   $options
     *
     * When the dispatch is complete, it will check to see if an array was
     * returned; if so, it will cast it to a view model using the
     * AcceptableViewModelSelector plugin, and the $acceptCriteria property.
     *
     * @param  MvcEvent $e
     * @return mixed
     * @throws DomainException
     */
    public function onDispatch(MvcEvent $e)
    {
        if (! $this->getResource()) {
            throw new DomainException(sprintf(
                '%s requires that a %s\ResourceInterface object is composed; none provided',
                __CLASS__,
                __NAMESPACE__
            ));
        }

        if (! $this->route) {
            throw new DomainException(sprintf(
                '%s requires that a route name for the resource is composed; none provided',
                __CLASS__
            ));
        }

        // Check for an API-Problem in the event
        $return = $e->getParam('api-problem', false);

        // If no return value dispatch the parent event
        if (! $return) {
            $return = parent::onDispatch($e);
        }

        if (! $return instanceof ApiProblem
            && ! $return instanceof HalEntity
            && ! $return instanceof HalCollection
        ) {
            return $return;
        }

        if ($return instanceof ApiProblem) {
            return new ApiProblemResponse($return);
        }

        // Set the fallback content negotiation to use HalJson.
        $e->setParam('ZFContentNegotiationFallback', 'HalJson');

        // Use content negotiation for creating the view model
        $viewModel = new ContentNegotiationViewModel(array('payload' => $return));
        $e->setResult($viewModel);

        return $viewModel;
    }
 /**
  * Handle the dispatch event
  *
  * Does several "pre-flight" checks:
  * - Raises an exception if no resource is composed.
  * - Raises an exception if no route is composed.
  * - Returns a 405 response if the current HTTP request method is not in
  *   $options
  *
  * When the dispatch is complete, it will check to see if an array was
  * returned; if so, it will cast it to a view model using the
  * AcceptableViewModelSelector plugin, and the $acceptCriteria property.
  *
  * @param  MvcEvent $e
  * @return mixed
  * @throws Exception\DomainException
  */
 public function onDispatch(MvcEvent $e)
 {
     if (!$this->resource) {
         throw new Exception\DomainException(sprintf('%s requires that a %s\\ResourceInterface object is composed; none provided', __CLASS__, __NAMESPACE__));
     }
     if (!$this->route) {
         throw new Exception\DomainException(sprintf('%s requires that a route name for the resource is composed; none provided', __CLASS__));
     }
     // Check for an API-Problem in the event
     $return = $e->getParam('api-problem', false);
     // If no API-Problem, dispatch the parent event
     if (!$return) {
         $return = parent::onDispatch($e);
     }
     if (!$return instanceof ApiProblem && !$return instanceof HalResource && !$return instanceof HalCollection) {
         return $return;
     }
     $viewModel = $this->acceptableViewModelSelector($this->acceptCriteria);
     $viewModel->setVariables(array('payload' => $return));
     if ($viewModel instanceof View\RestfulJsonModel) {
         $viewModel->setTerminal(true);
     }
     $e->setResult($viewModel);
     return $viewModel;
 }
 public function onDispatch(MvcEvent $event)
 {
     $collection = $this->params()->fromRoute('collection');
     if (!$this->settingsManager->has($collection)) {
         return new ApiProblemResponse(new ApiProblem(404, 'Settings collection not found.'));
     }
     $this->settings = $this->settingsManager->get($collection);
     return parent::onDispatch($event);
 }