Example #1
0
 /**
  * Route path
  *
  * @param BaseContext|Context $context
  * @return mixed
  */
 public function route(BaseContext $context)
 {
     $this->currentPath = $context;
     $router = new AliasRouter(app()->getCollector()->getRouteAliases());
     $alias = $router->route(new BaseContext($context->path()));
     if ($alias !== false) {
         $context = new Context((string) $alias, $context->domain(), $context->method(), $context->isSecure(), $context->request());
     }
     $result = parent::route($context);
     /** @var \Opis\Http\Request $request */
     $request = $context->request();
     /** @var \Opis\Http\Response $response */
     $response = $request->response();
     $response->body($result);
     $response->send();
     return $result;
 }
Example #2
0
 /**
  * Path constructor.
  * @param string $path
  * @param string $domain
  * @param string $method
  * @param bool $secure
  * @param mixed|null $request
  */
 public function __construct(string $path, string $domain = 'localhost', string $method = 'GET', bool $secure = false, $request = null)
 {
     $this->method = $method;
     $this->domain = $domain;
     $this->method = strtoupper($method);
     $this->secure = $secure;
     $this->request = $request;
     parent::__construct($path);
 }
Example #3
0
 /**
  * @param BaseRouter|BaseRouter $router
  * @param BaseContext|Context $context
  * @param BaseRoute|Route $route
  * @return bool
  */
 public function pass(BaseRouter $router, BaseContext $context, BaseRoute $route) : bool
 {
     //match secure
     if (null !== ($secure = $route->get('secure'))) {
         if ($secure !== $context->isSecure()) {
             return false;
         }
     }
     //match method
     if (!in_array($context->method(), $route->get('method', ['GET']))) {
         return false;
     }
     // match domain
     if (null !== ($domain = $route->get('domain'))) {
         $regex = $router->getRouteCollection()->getDomainCompiler()->getRegex($domain, $route->getWildcards());
         return preg_match($regex, $context->domain());
     }
     return true;
 }
Example #4
0
 /**
  * Constructor
  * 
  * @param   string  $name       Event's name
  * @param   boolean $cancelable (optional) Cancelable event
  */
 public function __construct(string $name, bool $cancelable = false)
 {
     $this->eventName = $name;
     $this->cancelable = $cancelable;
     parent::__construct($name);
 }