Example #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);
 }
Example #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;
 }
Example #3
0
 /**
  * Setup parameter containers
  *
  * @param HttpCargoInterface $cargo
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 protected function setupParameters(HttpCargoInterface $cargo)
 {
     $cargo->getRequestParameters()->setFromArray($_GET);
     $cargo->getEnvironmentParameters()->setFromArray($_ENV);
     $cargo->getServerParameters()->setFromArray($_SERVER);
 }