getLocalVar() 공개 메소드

Each request has its own mutable local storage to which application callables and middleware may read and write data. Other callables which are aware of this data can then access it without the server being tightly coupled to specific implementations.
public getLocalVar ( string $key ) : mixed
$key string
리턴 mixed
예제 #1
0
파일: Root.php 프로젝트: kelunik/aerys
 /**
  * Respond to HTTP requests for filesystem resources
  */
 public function __invoke(Request $request, Response $response)
 {
     $uri = $request->getLocalVar("aerys.sendfile") ?: $request->getUri();
     $path = ($qPos = \strpos($uri, "?")) ? \substr($uri, 0, $qPos) : $uri;
     // IMPORTANT! Do NOT remove this. If this is left in, we'll be able to use /path\..\../outsideDocRoot defeating the removeDotPathSegments() function! (on Windows at least)
     $path = \str_replace("\\", "/", $path);
     $path = self::removeDotPathSegments($path);
     // We specifically break the lookup generator out into its own method
     // so that we can potentially avoid forcing the server to resolve a
     // coroutine when the file is already cached.
     return ($fileInfo = $this->fetchCachedStat($path, $request)) ? $this->respond($fileInfo, $request, $response) : $this->respondWithLookup($this->root . $path, $path, $request, $response);
 }
예제 #2
0
 public function __construct(Request $request)
 {
     $this->request = $request;
     $config = $request->getLocalVar("aerys.session.config");
     assert(\is_array($config), 'No middleware was loaded or Aerys\\Session class instantiated in invalid context');
     $this->driver = $config["driver"];
     $config += static::CONFIG;
     $request->setLocalVar("aerys.session.config", $config);
     $id = $request->getCookie($config["name"]);
     if (\strlen($id) === self::ID_LENGTH && strspn($id, self::ALLOWED_ID_CHARS) === self::ID_LENGTH) {
         $this->setId($id);
     }
     $this->ttl = $config["ttl"];
     $this->maxlife = $config["maxlife"];
 }
예제 #3
0
파일: Router.php 프로젝트: amphp/aerys
 /**
  * Route a request
  *
  * @param \Aerys\Request $request
  * @param \Aerys\Response $response
  */
 public function __invoke(Request $request, Response $response)
 {
     if (!($preRoute = $request->getLocalVar("aerys.routed"))) {
         return;
     }
     list($isMethodAllowed, $data) = $preRoute;
     if ($isMethodAllowed) {
         return $data($request, $response, $request->getLocalVar("aerys.routeArgs"));
     } else {
         $allowedMethods = implode(",", $data);
         $response->setStatus(HTTP_STATUS["METHOD_NOT_ALLOWED"]);
         $response->setHeader("Allow", $allowedMethods);
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
     }
 }
예제 #4
0
파일: Root.php 프로젝트: hunslater/aerys
 /**
  * Respond to HTTP requests for filesystem resources
  *
  * @param \Aerys\Request $request
  * @return mixed
  */
 public function __invoke(Request $request, Response $response)
 {
     $uri = $request->getLocalVar("aerys.sendfile") ?: $request->getUri();
     $path = ($qPos = \stripos($uri, "?")) ? \substr($uri, 0, $qPos) : $uri;
     $path = $reqPath = \str_replace("\\", "/", $path);
     $path = $this->root . $path;
     $path = self::removeDotPathSegments($path);
     // IMPORTANT!
     // Protect against dot segment path traversal above the document root by
     // verifying that the path actually resides in the document root.
     if (\strpos($path, $this->root) !== 0) {
         $response->setStatus(HTTP_STATUS["FORBIDDEN"]);
         $response->setHeader("Aerys-Generic-Response", "enable");
         $response->end();
     }
     // We specifically break the lookup generator out into its own method
     // so that we can potentially avoid forcing the server to resolve a
     // coroutine when the file is already cached.
     return ($fileInfo = $this->fetchCachedStat($reqPath, $request)) ? $this->respond($fileInfo, $request, $response) : $this->respondWithLookup($path, $reqPath, $request, $response);
 }
예제 #5
0
파일: Server.php 프로젝트: amphp/aerys
 private function sendPreAppTraceResponse(Request $request, Response $response)
 {
     $response->setStatus(HTTP_STATUS["OK"]);
     $response->setHeader("Content-Type", "message/http");
     $response->end($request->getLocalVar('aerys.trace'));
 }
예제 #6
0
 public function handle(Request $request, Response $response, array $args)
 {
     $endpoint = $request->getLocalVar("chat.api.endpoint");
     $user = $request->getLocalVar("chat.api.user");
     if (!$endpoint || !$user) {
         // if this happens, something's really wrong, e.g. wrong order of callables
         $response->setStatus(500);
         $response->send("");
     }
     foreach ($args as $key => $arg) {
         if (is_numeric($arg)) {
             $args[$key] = (int) $arg;
         }
     }
     foreach ($request->getQueryVars() as $key => $value) {
         // Don't allow overriding URL parameters
         if (isset($args[$key])) {
             continue;
         }
         if (is_numeric($value)) {
             $args[$key] = (int) $value;
         } else {
             if (is_string($value)) {
                 $args[$key] = $value;
             } else {
                 $result = new Error("bad_request", "invalid query parameter types", 400);
                 $this->writeResponse($request, $response, $result);
                 return;
             }
         }
     }
     $args = $args ? (object) $args : new stdClass();
     $body = (yield $request->getBody());
     $payload = $body ? json_decode($body) : null;
     $result = (yield $this->chat->process(new StandardRequest($endpoint, $args, $payload), $user));
     $this->writeResponse($request, $response, $result);
 }