Пример #1
0
 /**
  * Constructor
  *
  * @param ObjectConfig $config  An optional ObjectConfig object with configuration options
  * @return DispatcherRequest
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Set the trusted proxies
     $this->setProxies(ObjectConfig::unbox($config->proxies));
     //Set files parameters
     $this->setFiles($config->files);
     //Set cookie parameters
     $this->setCookies($config->cookies);
     //Set the base URL
     $this->setBaseUrl($config->base_url);
     //Set the base path
     $this->setBasePath($config->base_path);
     //Set the formats
     foreach (ObjectConfig::unbox($config->formats) as $format => $mimetypes) {
         $this->addFormat($format, $mimetypes);
     }
     //Set document root for IIS
     if (!isset($_SERVER['DOCUMENT_ROOT'])) {
         if (isset($_SERVER['SCRIPT_FILENAME'])) {
             $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
         }
         if (isset($_SERVER['PATH_TRANSLATED'])) {
             $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])));
         }
     }
     //Set the authorization
     if (!isset($_SERVER['PHP_AUTH_USER'])) {
         /*
          * If you are running PHP as CGI. Apache does not pass HTTP Basic user/pass to PHP by default.
          * To fix this add these lines to your .htaccess file:
          *
          * RewriteCond %{HTTP:Authorization} ^(.+)$
          * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
          */
         //When using PHP-FPM HTTP_AUTHORIZATION is called REDIRECT_HTTP_AUTHORIZATION
         if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
             $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
         }
         // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
         if (isset($_SERVER['HTTP_AUTHORIZATION']) && stripos($_SERVER['HTTP_AUTHORIZATION'], 'basic') === 0) {
             $exploded = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
             if (count($exploded) == 2) {
                 list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = $exploded;
             }
         }
     }
     //Set the headers
     $headers = array();
     foreach ($_SERVER as $key => $value) {
         if ($value && strpos($key, 'HTTP_') === 0) {
             // Cookies are handled using the $_COOKIE superglobal
             if (strpos($key, 'HTTP_COOKIE') === 0) {
                 continue;
             }
             $headers[substr($key, 5)] = $value;
         } elseif ($value && strpos($key, 'CONTENT_') === 0) {
             $name = substr($key, 8);
             // Content-
             $name = 'Content-' . ($name == 'MD5' ? $name : ucfirst(strtolower($name)));
             $headers[$name] = $value;
         }
     }
     if (isset($_SERVER['PHP_AUTH_USER'])) {
         $headers['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
         $headers['PHP_AUTH_PW'] = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
     }
     $this->_headers->add($headers);
     //Set the version
     if (isset($_SERVER['SERVER_PROTOCOL']) && strpos($_SERVER['SERVER_PROTOCOL'], '1.0') !== false) {
         $this->setVersion('1.0');
     }
     //Set request data
     if ($this->getContentType() == 'application/x-www-form-urlencoded') {
         if (in_array($this->getMethod(), array('PUT', 'DELETE', 'PATCH'))) {
             parse_str($this->getContent(), $data);
             $this->data->add($data);
         }
     }
     if ($this->getContentType() == 'application/json') {
         if (in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) {
             $data = json_decode($this->getContent(), true);
             $this->data->add($data);
         }
     }
 }
Пример #2
0
 /**
  * Constructor
  *
  * @param ObjectConfig $config  An optional ObjectConfig object with configuration options
  */
 public function __construct(ObjectConfig $config)
 {
     parent::__construct($config);
     //Create the transport queue
     $this->_queue = $this->getObject('lib:object.queue');
     //Attach the request transport handlers
     $transports = (array) ObjectConfig::unbox($config->transports);
     foreach ($transports as $key => $value) {
         if (is_numeric($key)) {
             $this->attachTransport($value);
         } else {
             $this->attachTransport($key, $value);
         }
     }
     //Set the trusted proxies
     $this->setProxies(ObjectConfig::unbox($config->proxies));
     //Set files parameters
     $this->setFiles($config->files);
     //Set cookie parameters
     $this->setCookies($config->cookies);
     //Set the base URL
     $this->setBaseUrl($config->base_url);
     //Set the base path
     $this->setBasePath($config->base_path);
     //Set the formats
     foreach (ObjectConfig::unbox($config->formats) as $format => $mimetypes) {
         $this->addFormat($format, $mimetypes);
     }
     //Receive the request
     $this->receive();
     // Set timezone to user's settings
     date_default_timezone_set($this->getTimezone());
     // Set language to user's settings
     locale_set_default($this->getLanguage());
 }