/**
  * Get system Uri object.
  *
  * @param   string  $requestUri  The request uri string.
  * @param   bool    $refresh     Refresh the uri.
  *
  * @return  PsrUri  The system Uri object.
  *
  * @since   2.0
  */
 protected function getSystemUri($requestUri = null, $refresh = false)
 {
     if ($this->psrUri && !$refresh) {
         return $this->psrUri;
     }
     $uri = $requestUri ? new PsrUri($requestUri) : $this->getRequest()->getUri();
     $server = $this->getRequest()->getServerParams();
     // If we are working from a CGI SAPI with the 'cgi.fix_pathinfo' directive disabled we use PHP_SELF.
     if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($server['REQUEST_URI'])) {
         // We aren't expecting PATH_INFO within PHP_SELF so this should work.
         $uri = $uri->withPath(rtrim(dirname(ServerHelper::getValue($server, 'PHP_SELF')), '/\\'));
     } else {
         $uri = $uri->withPath(rtrim(dirname(ServerHelper::getValue($server, 'SCRIPT_NAME')), '/\\'));
     }
     // Clear the unused parts of the requested URI.
     $uri = $uri->withFragment('');
     return $this->psrUri = $uri;
 }
Exemple #2
0
 /**
  * Create a new instance with the specified uploaded files.
  *
  * This method MUST be implemented in such a way as to retain the
  * immutability of the message, and MUST return an instance that has the
  * updated body parameters.
  *
  * @param  array  $uploadedFiles  An array tree of UploadedFileInterface instances.
  *
  * @return static
  * @throws \InvalidArgumentException if an invalid structure is provided.
  */
 public function withUploadedFiles(array $uploadedFiles)
 {
     if (!ServerHelper::validateUploadedFiles($uploadedFiles)) {
         throw new \InvalidArgumentException('Invalid uploaded files, every file should be an UploadedInterface');
     }
     $new = clone $this;
     $new->uploadedFiles = $uploadedFiles;
     return $new;
 }
    /**
     * testParseFormData
     *
     * @return  void
     *
     * @covers \Windwalker\Http\Helper\ServerHelper::parseFormData
     */
    public function testParseFormData()
    {
        $type = 'multipart/form-data; boundary=----WebKitFormBoundary8zi5vcW6H9OgqKSj';
        $input = <<<DATA
------WebKitFormBoundary8zi5vcW6H9OgqKSj
Content-Disposition: form-data; name="flower"

SAKURA
------WebKitFormBoundary8zi5vcW6H9OgqKSj
Content-Disposition: form-data; name="tree"

Marabutan
------WebKitFormBoundary8zi5vcW6H9OgqKSj
Content-Disposition: form-data; name="fruit"

Apple
------WebKitFormBoundary8zi5vcW6H9OgqKSj--
DATA;
        $input = str_replace("\r\n", "\n", $input);
        $input = str_replace("\n", "\r\n", $input);
        $this->assertEquals(array('data' => array('flower' => 'SAKURA', 'tree' => 'Marabutan', 'fruit' => 'Apple'), 'files' => array()), ServerHelper::parseFormData($input));
    }
 /**
  * Get the base URI for the $_SERVER superglobal.
  *
  * Try to auto detect the base URI from different server system including IIS and Apache.
  *
  * This method based on ZF2's Zend\Http\PhpEnvironment\Request class
  *
  * @see  https://github.com/zendframework/zend-http/blob/master/src/PhpEnvironment/Request.php
  *
  * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  * @license   http://framework.zend.com/license/new-bsd New BSD License
  *
  * @param array $server
  *
  * @return string
  */
 public static function getRequestUri(array $server)
 {
     // IIS7 with URL Rewrite: make sure we get the unencoded url
     // (double slash problem).
     $iisUrlRewritten = ServerHelper::getValue($server, 'IIS_WasUrlRewritten');
     $unencodedUrl = ServerHelper::getValue($server, 'UNENCODED_URL', '');
     if ('1' == $iisUrlRewritten && !empty($unencodedUrl)) {
         return $unencodedUrl;
     }
     $requestUri = ServerHelper::getValue($server, 'REQUEST_URI');
     // Check this first so IIS will catch.
     $httpXRewriteUrl = ServerHelper::getValue($server, 'HTTP_X_REWRITE_URL');
     if ($httpXRewriteUrl !== null) {
         $requestUri = $httpXRewriteUrl;
     }
     // Check for IIS 7.0 or later with ISAPI_Rewrite
     $httpXOriginalUrl = ServerHelper::getValue($server, 'HTTP_X_ORIGINAL_URL');
     if ($httpXOriginalUrl !== null) {
         $requestUri = $httpXOriginalUrl;
     }
     if ($requestUri !== null) {
         return preg_replace('#^[^/:]+://[^/]+#', '', $requestUri);
     }
     $origPathInfo = ServerHelper::getValue($server, 'ORIG_PATH_INFO');
     if (empty($origPathInfo)) {
         return '/';
     }
     return $origPathInfo;
 }