/** * Constructor */ public function __construct() { parent::__construct(); $this->prepare(); $this->setPost($_POST); $this->setGet($_GET); $this->setFile($_FILES); $this->setScriptFile($_SERVER['SCRIPT_NAME'])->setServer($_SERVER['SERVER_NAME'])->setMethod($_SERVER['REQUEST_METHOD'])->setProtocol($_SERVER['SERVER_PROTOCOL'])->setPort($_SERVER['SERVER_PORT'])->setIp($_SERVER['REMOTE_ADDR']); if (isset($_SERVER['REQUEST_URI'])) { $this->setUri($_SERVER['REQUEST_URI']); } else { $this->setUri($_SERVER['PHP_SELF']); } if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { $this->setAjax(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); } return $this; }
/** * Process request path with route pattern, retrieve parameters * * @param Request $request Source request * @param Route $route Route to be processed * * @return boolean */ protected function process($request, $route) { $path = $route->getPath(); if (preg_match($path->getRegExp(), $request->getPath())) { foreach ($path->getSegments() as $segment) { $values = array(); if (preg_match($segment->getRegExp(), $request->getPath(), $values)) { unset($values[0]); $values = array_values($values); $names = array_keys($segment->getParams()); $params = !empty($names) && count($names) == count($values) ? array_combine($names, $values) : array(); $params = $this->processParams($route, $params); $request->setParams($params); return true; } } } return false; }
/** * Get current URL * * @return string */ public function getCurrentUrl() { $url = $this->request->getUri(); return $url; }