Пример #1
0
 /**
  * Prepares and returns the array with the FastCGI environment variables.
  *
  * @param \AppserverIo\Psr\HttpMessage\RequestInterface          $request        A request object
  * @param \AppserverIo\Server\Interfaces\RequestContextInterface $requestContext A requests context instance
  *
  * @return array The array with the prepared FastCGI environment variables
  */
 protected function prepareEnvironment(RequestInterface $request, RequestContextInterface $requestContext)
 {
     // prepare the Fast-CGI environment variables
     $environment = array(ServerVars::GATEWAY_INTERFACE => 'FastCGI/1.0', ServerVars::REQUEST_METHOD => $requestContext->getServerVar(ServerVars::REQUEST_METHOD), ServerVars::SCRIPT_FILENAME => $requestContext->getServerVar(ServerVars::SCRIPT_FILENAME), ServerVars::QUERY_STRING => $requestContext->getServerVar(ServerVars::QUERY_STRING), ServerVars::SCRIPT_NAME => $requestContext->getServerVar(ServerVars::SCRIPT_NAME), ServerVars::REQUEST_URI => $requestContext->getServerVar(ServerVars::REQUEST_URI), ServerVars::DOCUMENT_ROOT => $requestContext->getServerVar(ServerVars::DOCUMENT_ROOT), ServerVars::SERVER_PROTOCOL => $requestContext->getServerVar(ServerVars::SERVER_PROTOCOL), ServerVars::HTTPS => $requestContext->getServerVar(ServerVars::HTTPS), ServerVars::SERVER_SOFTWARE => $requestContext->getServerVar(ServerVars::SERVER_SOFTWARE), ServerVars::REMOTE_ADDR => $requestContext->getServerVar(ServerVars::REMOTE_ADDR), ServerVars::REMOTE_PORT => $requestContext->getServerVar(ServerVars::REMOTE_PORT), ServerVars::SERVER_ADDR => $requestContext->getServerVar(ServerVars::SERVER_ADDR), ServerVars::SERVER_PORT => $requestContext->getServerVar(ServerVars::SERVER_PORT), ServerVars::SERVER_NAME => $requestContext->getServerVar(ServerVars::SERVER_NAME));
     // if we found a redirect status, add it to the environment variables
     if ($requestContext->hasServerVar(ServerVars::REDIRECT_STATUS)) {
         $environment[ServerVars::REDIRECT_STATUS] = $requestContext->getServerVar(ServerVars::REDIRECT_STATUS);
     }
     // if we found a redirect URL, add it to the environment variables
     if ($requestContext->hasServerVar(ServerVars::REDIRECT_URL)) {
         $environment[ServerVars::REDIRECT_URL] = $requestContext->getServerVar(ServerVars::REDIRECT_URL);
     }
     // if we found a redirect URI, add it to the environment variables
     if ($requestContext->hasServerVar(ServerVars::REDIRECT_URI)) {
         $environment[ServerVars::REDIRECT_URI] = $requestContext->getServerVar(ServerVars::REDIRECT_URI);
     }
     // if we found a Content-Type header, add it to the environment variables
     if ($request->hasHeader(Protocol::HEADER_CONTENT_TYPE)) {
         $environment['CONTENT_TYPE'] = $request->getHeader(Protocol::HEADER_CONTENT_TYPE);
     }
     // if we found a Content-Length header, add it to the environment variables
     if ($request->hasHeader(Protocol::HEADER_CONTENT_LENGTH)) {
         $environment['CONTENT_LENGTH'] = $request->getHeader(Protocol::HEADER_CONTENT_LENGTH);
     }
     // create an HTTP_ environment variable for each header
     foreach ($request->getHeaders() as $key => $value) {
         $environment['HTTP_' . str_replace('-', '_', strtoupper($key))] = $value;
     }
     // create an HTTP_ environment variable for each server environment variable
     foreach ($requestContext->getEnvVars() as $key => $value) {
         $environment[$key] = $value;
     }
     // return the prepared environment
     return $environment;
 }