コード例 #1
0
 /**
  * Method to test getValue().
  *
  * @return void
  *
  * @covers \Windwalker\Http\Helper\ServerHelper::getValue
  */
 public function testGetValue()
 {
     $servers = array('HTTP_FOO' => 'foo', 'X_BAR' => 'bar', 'CONTENT_BAZ' => array('baz'));
     $this->assertEquals(ServerHelper::getValue($servers, 'HTTP_FOO'), 'foo');
     $this->assertEquals(ServerHelper::getValue($servers, 'HTTP_BAR'), null);
     $this->assertEquals(ServerHelper::getValue($servers, 'x_bar'), null);
     $this->assertEquals(ServerHelper::getValue($servers, 'x_bar', 'default'), 'default');
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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;
 }