コード例 #1
0
ファイル: JsonToArray.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #2
0
ファイル: ThrowableToText.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #3
0
ファイル: ArrayToJson.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #4
0
ファイル: HttpHub.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #5
0
ファイル: ViewRender.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #6
0
ファイル: HttpErrorHub.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #7
0
ファイル: ActionController.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #8
0
ファイル: RestfulController.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #9
0
ファイル: Application.php プロジェクト: fixin/fixin
 /**
  * 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());
     }
 }
コード例 #10
0
ファイル: Route.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }
コード例 #11
0
ファイル: WrapInView.php プロジェクト: fixin/fixin
 /**
  * {@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;
 }