public function __construct(Configuration $config, RequestInterface $request) { $this->_uriComponents = array(); $this->_config = $config; $requestHeaders = $request->getHeaders(); $this->scheme($request->isSecure() ? 'https' : 'http'); if (isset($requestHeaders['host'])) { $this->host($requestHeaders['host']); } // set the port number using the one from the Request, or the default // for the request scheme if ($request->getPort()) { $this->port($request->getPort()); } else { if ('http' == $this->_uriComponents['scheme']) { $this->port(80); } else { if ('ftp' == $this->_uriComponents['scheme']) { $this->port(21); } } } $this->_queryParams = $request->getQueryParams(); $requestUri = $request->getRequestUri(); if (($hashOffset = strpos('#', $requestUri)) !== FALSE) { $this->replacePath(strstr($requestUri, '#', true)); $this->fragment(substr(strstr($requestUri, '#'), 1)); } else { $this->replacePath($requestUri); } }
/** * Construct a flat array of method arguments for the resource method. * * @param Route $route The route being processed. * @param ReflectionMethod $method The resource class method that arguments * are needed for. * * @return array */ protected function _getResourceMethodArguments(Route $route, ReflectionMethod $method) { $clsRenderable = 'Sonno\\Application\\Renderable'; $pathParamValues = $this->_uriInfo->getPathParameters(); $queryParamValues = $this->_uriInfo->getQueryParameters(); $headerParamValues = $this->_request->getHeaders(); $pathParams = $route->getPathParams() ?: array(); $queryParams = $route->getQueryParams() ?: array(); $headerParams = $route->getHeaderParams() ?: array(); $formParams = $route->getFormParams() ?: array(); $resourceMethodArgs = array(); parse_str($this->_request->getRequestBody(), $formParamValues); foreach ($method->getParameters() as $idx => $reflParam) { $parameterName = $reflParam->getName(); $parameterClass = $reflParam->getClass(); // if the parameter is a type that implements Renderable, use the // implementation's unrender() function to generate an instance // of the class from the request body as the parameter value if (null !== $parameterClass && $parameterClass->implementsInterface($clsRenderable)) { $parameterClassName = $parameterClass->getName(); $parameterValue = $parameterClassName::unrender($this->_request->getRequestBody(), new Variant(null, null, $this->_request->getContentType())); $resourceMethodArgs[$idx] = $parameterValue; } // search for an argument value in the Path parameter collection if (in_array($parameterName, $pathParams) && isset($pathParamValues[$parameterName])) { $resourceMethodArgs[$idx] = $pathParamValues[$parameterName]; } // search for an argument value in the Query parameter collection if (in_array($parameterName, $queryParams) && isset($queryParamValues[$parameterName])) { $resourceMethodArgs[$idx] = $queryParamValues[$parameterName]; } // search for an argument value in the Header parameter collection if (in_array($parameterName, $headerParams) && isset($headerParamValues[$parameterName])) { $resourceMethodArgs[$idx] = $headerParamValues[$parameterName]; } // search for an argument value in the Form parameter collection if (in_array($parameterName, $formParams) && isset($formParamValues[$parameterName])) { $resourceMethodArgs[$idx] = $formParamValues[$parameterName]; } } return $resourceMethodArgs; }