示例#1
0
 /**
  * Handle observed path
  *
  * @param HttpCargoInterface $cargo
  * @param string $path
  * @throws RuntimeException
  * @return HttpCargoInterface
  */
 protected function handlePath(HttpCargoInterface $cargo, string $path) : HttpCargoInterface
 {
     $depth = $this->depth;
     $tags = explode('/', rtrim($path, '/'), $depth + 2);
     if (!isset($tags[$depth + 1])) {
         // Action
         if (isset($tags[$depth])) {
             $cargo->getRequestParameters()->set('action', $tags[$depth]);
         }
         // Controller
         if ($controller = $this->pathToController(implode('\\', array_slice($tags, 0, $depth)))) {
             return $controller->handle($cargo);
         }
     }
     return $cargo->setStatusCode(Http::STATUS_NOT_FOUND_404);
 }
示例#2
0
 /**
  * {@inheritDoc}
  * @see \Fixin\Delivery\Node\HttpHub::handleHttpCargo($cargo)
  */
 public function handleHttpCargo(HttpCargoInterface $cargo) : CargoInterface
 {
     $segments = explode('/', trim($cargo->getRequestUri()->getPath(), '/'));
     $count = count($segments);
     if (isset($this->routeTree[$count]) && false !== ($found = $this->findHandler($segments, $this->routeTree[$count], []))) {
         $cargo->getRequestParameters()->setFromArray($found[static::KEY_PARAMETERS]);
         return $this->getHandler($found[static::KEY_HANDLER])->handle($cargo);
     }
     return $cargo;
 }
示例#3
0
 /**
  * {@inheritDoc}
  * @see \Fixin\Delivery\Node\HttpHub::handleHttpCargo($cargo)
  */
 protected function handleHttpCargo(HttpCargoInterface $cargo) : CargoInterface
 {
     return $cargo->setStatusCode(Http::STATUS_NOT_FOUND_404);
 }
示例#4
0
 /**
  * Setup request data
  *
  * @param HttpCargoInterface $cargo
  */
 protected function setupRequest(HttpCargoInterface $cargo)
 {
     $cargo->setRequestProtocolVersion($this->getProtocolVersion())->setRequestMethod($this->getMethod())->setRequestUri($this->container->clonePrototype('Base\\Uri\\Factory\\EnvironmentUriFactory'))->setRequestHeaders($this->getHeaders());
 }
示例#5
0
 /**
  * Reply: Method not allowed
  *
  * @param HttpCargoInterface $cargo
  * @return HttpCargoInterface
  */
 protected function replyMethodNotAllowed(HttpCargoInterface $cargo) : HttpCargoInterface
 {
     return $cargo->setContent(static::CONTENT_METHOD_NOT_ALLOWED)->setContentType(static::CONTENT_TYPE)->setStatusCode(Http::STATUS_METHOD_NOT_ALLOWED_405);
 }
示例#6
0
 /**
  * Reply: Not Found (404)
  *
  * @param HttpCargoInterface $cargo
  * @return HttpCargoInterface
  */
 protected function replyNotFound(HttpCargoInterface $cargo) : HttpCargoInterface
 {
     return $cargo->setStatusCode(Http::STATUS_NOT_FOUND_404);
 }