public function __construct(Request $req) { $this->mapkey = $req->getMapStack(); $this->ajax = (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); $this->params = $req->parseParams(); $this->url = $_SERVER['REQUEST_URI']; $this->path = $_SERVER['QUERY_PATH']; $this->method = strtolower($_SERVER['REQUEST_METHOD']); if (isset($_SERVER['SERVER_PROTOCOL'])) { $this->protocol = $_SERVER['SERVER_PROTOCOL']; } if (isset($_SERVER['SERVER_PORT'])) { $this->port = (int) $_SERVER['SERVER_PORT']; } if (isset($_SERVER['SERVER_NAME'])) { $this->host = $_SERVER['SERVER_NAME']; } $this->secure = self::isHTTPS(); if (isset($_SERVER['HTTP_REFERER'])) { $this->referer = $_SERVER['HTTP_REFERER']; } }
private function resolve(array $source, RequestBuilder &$req, ResponseBuilder &$res, \stdClass &$call) { if ($source) { foreach ($source as $mwobject) { $class = '\\olifant\\middleware\\' . $mwobject; $middle = new $class(); $instance = '\\olifant\\middleware\\MiddlewareBase'; if (false === is_subclass_of($middle, $instance)) { throw new AppException('Class ' . $class . ' is not instanceof ' . $instance); } if (isset($middle->path) or isset($middle->exceptPath)) { $uri = rawurldecode(Request::cleanUri($req->path)); $mode = isset($middle->path) ? false : (isset($middle->exceptPath) ? true : false); $target = isset($middle->path) ? $middle->path : (isset($middle->exceptPath) ? $middle->exceptPath : null); if (is_array($target)) { $match = false; foreach ($target as $p) { if (Router::compare($p, $uri)) { $match = true; break; } } if ($mode === $match) { continue; } } else { if ($mode === Router::compare($target, $uri)) { continue; } } } call_user_func_array(array($middle, 'handle'), array($req, $res, $call)); } } return $this; }