/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if (in_array($cargo->getContentType(), static::ALLOWED_TYPES)) { $cargo->setContent($this->container->get('Base\\Json\\Json')->decode($cargo->getContent())); } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if ($cargo->getContent() instanceof \Throwable) { $cargo->setContent(Ground::debugText(htmlspecialchars($cargo->getContent())))->setContentType(static::CONTENT_TYPE); } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if (is_array($cargo->getContent())) { $cargo->setContent($this->container->get('Base\\Json\\Json')->encode($cargo->getContent()))->setContentType(static::CONTENT_TYPE); } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if ($cargo instanceof HttpCargoInterface && $cargo->getStatusCode() === Http::STATUS_CONTINUE_100) { return $this->handleHttpCargo($cargo); } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { $content = $cargo->getContent(); if ($content instanceof ViewInterface) { $cargo->setContent($content->render())->setContentType($content->getContentType()); } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if ($cargo instanceof HttpCargoInterface) { $statusCode = $cargo->getStatusCode(); if ($statusCode >= Http::STATUS_BAD_REQUEST_400 && $statusCode <= Http::STATUS_LAST_POSSIBLE_ERROR) { return $this->getRoute()->handle($cargo)->setDelivered(true); } } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if ($cargo instanceof HttpCargoInterface) { if ($method = $this->getActionMethodName($cargo->getRequestParameters()->get(static::ACTION_PARAMETER, static::DEFAULT_ACTION))) { return $this->handleMethod($cargo, $method); } return $this->replyNotFound($cargo); } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if ($cargo instanceof HttpCargoInterface) { $method = $cargo->getRequestMethod(); if (isset(static::METHOD_MAP[$method])) { return $this->{static::METHOD_MAP[$method]}($cargo->setStatusCode(Http::STATUS_OK_200)); } return $this->replyMethodNotAllowed($cargo); } return $cargo; }
/** * Error route * * @param CargoInterface $cargo */ protected function errorRoute(CargoInterface $cargo) { // HTTP cargo if ($cargo instanceof HttpCargoInterface) { $cargo->setStatusCode(Http::STATUS_INTERNAL_SERVER_ERROR_500); } try { $cargo = $this->container->get($this->config[static::OPTION_ERROR_ROUTE])->handle($cargo); $cargo->unpack(); } catch (\Throwable $t) { // Double error $this->internalServerError($t->getMessage()); } }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { $cargo->setDelivered(false); $index = 0; $length = count($this->nodes); while ($index < $length) { $cargo = $this->getNode($index)->handle($cargo); if ($cargo->isDelivered()) { break; } $index++; } return $cargo; }
/** * {@inheritDoc} * @see \Fixin\Delivery\Cargo\CargoHandlerInterface::handle($cargo) */ public function handle(CargoInterface $cargo) : CargoInterface { if (in_array($cargo->getContentType(), static::ALLOWED_TYPES)) { $content = $cargo->getContent(); $view = $this->container->clonePrototype('View\\View'); $view->setTemplate($this->template); $cargo->setContent($view); if ($content instanceof ViewInterface) { $view->setChild($this->contentName, $content); return $cargo; } $view->setVariable($this->contentName, $content); } return $cargo; }