Пример #1
0
 public function canResolve(Context $context)
 {
     $uri = $context->getRequest()->getUrl();
     $u = ltrim($uri, "/");
     $ns = ltrim($this->ns, "/");
     return substr($u, 0, strlen($ns)) == $ns;
 }
 public function create(Context $context, $paramName)
 {
     $headers = $context->getRequest()->getHeaders();
     $msg = new Message();
     $created = isset($headers['created']) ? $headers['created'] : null;
     $expiration = isset($headers['expiration']) ? $headers['expiration'] : null;
     $msg->setHeaders($headers);
     $msg->setExpiration($expiration);
     $msg->setCreated($created);
     return $msg;
 }
Пример #3
0
 public function call(Context $context)
 {
     $currentHost = $context->getRequest()->getHost();
     $currentProtocol = $context->getRequest()->getProtocol();
     $currentUrl = $context->getRequest()->getUrl();
     $currentMethod = $context->getRequest()->getHttpMethod();
     // Identify current Command; register RouteMap & params with Context
     $route;
     try {
         $route = $this->routeMap->getRoute($context->getRequest());
     } catch (RouteException $e) {
         throw new NotFoundException(sprintf("Route not found for request: %s %s://%s%s", $currentMethod, $currentProtocol, $currentHost, $currentUrl));
     }
     $context->setProp(self::CURRENT_ROUTE, $route);
     // Force pages to their designated protocol if specified
     if ($route->getProtocol() != null) {
         if ($currentProtocol != $route->getProtocol()) {
             $url = Url::fromString(sprintf("%s://%s/", $route->getProtocol(), $currentHost))->join($currentUrl)->addParams($_GET);
             throw new RedirectException('Change Protocol', 301, $url);
         }
     }
     $this->wrappedApp->call($context);
 }
Пример #4
0
 public function call(Context $context)
 {
     $currentUrl = $context->getRequest()->getUrl();
     $currentMethod = $context->getRequest()->getHttpMethod();
     if ($currentMethod == Http::METHOD_GET) {
         $lintedPath = $this->lintPath($currentUrl);
         if ((string) $currentUrl != $lintedPath) {
             $protocol = $context->getRequest()->getProtocol();
             $host = $context->getRequest()->getHost();
             if ($this->redirect) {
                 $url = Url::fromParts(['scheme' => $protocol, 'host' => $host, 'path' => $lintedPath, 'query' => $this->arrayToQuery($context->getRequest()->getGetParams())]);
                 throw new RedirectException("Linting Url and redirecting browser", 301, $url);
             } else {
                 $context->getRequest()->setUrl($lintedPath);
             }
         }
     }
     $this->wrappedApp->call($context);
 }