/** * @param string $originalUri * @param string $httpMethod * * @param RequestParams $params * * @return RoutePart * * @throws PathNotFoundException When it was not possible to find a matching route. */ public function handle($originalUri, $httpMethod, RequestParams $params = null) { if ($params === null) { $params = new RequestParams(new RequestParamBuilder()); } $uri = $this->stripTrailingSlash($originalUri); $uri = $this->removeQueryParametersFromTheUri($uri); $url = parse_url($uri); $effectiveUri = $url['path']; $route = $this->getRouteForUriAndMethod($httpMethod, $effectiveUri); $handler = $this->getHandlerForUri($httpMethod, $route, $effectiveUri); $uriParams = $route->parameters($uri); foreach ($uriParams as $name => $value) { $params->add($name, $value); } $originalUrl = parse_url($originalUri); if (array_key_exists('query', $originalUrl)) { parse_str($originalUrl['query'], $queryParams); foreach ($queryParams as $name => $value) { $params->add($name, $value); } } $handler->setParameters($params); return $handler; }
public function __construct($all = array()) { $headers = array(); // all should be the contents of $_SERVER foreach ($all as $key => $value) { // All the request headers start with HTTP_ in the _SERVER array if (strpos($key, 'HTTP_') === 0) { // Convert to a standard notation. X_REQUESTED_WITH => X-Requested-With $name = $this->cleanNames(substr($key, 5)); $headers[$name] = $value; } elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) { // Except for the ones that don't start HTTP ffs $headers[$this->cleanNames($key)] = $value; } } // Look for auth user and password while we are here... if (isset($all['PHP_AUTH_USER'])) { $password = ''; if (isset($all['PHP_AUTH_PW'])) { $password = $all['PHP_AUTH_PW']; } $headers['Auth-User'] = $all['PHP_AUTH_USER']; $headers['Auth-Password'] = $password; } // Pass this on to the base class - we are down to just the headers now // with all the other crap removed. parent::__construct($headers); }
/** * Set userland parameters * * @param array $params * @return void */ public function setParams(array $params) { $this->params->merge($params); }