getLocalVar() public method

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
return 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
ファイル: Session.php プロジェクト: amphp/aerys-session
 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
ファイル: Dispatcher.php プロジェクト: kelunik/chat-api
 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);
 }