web/lib/Zend/Controller/Request/Http.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Controller
    16  * @package    Zend_Controller
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Http.php 23414 2010-11-20 10:56:11Z bittarman $
    19  * @version    $Id: Http.php 24842 2012-05-31 18:31:28Z rob $
    20  */
    20  */
    21 
    21 
    22 /** @see Zend_Controller_Request_Abstract */
    22 /** @see Zend_Controller_Request_Abstract */
    23 require_once 'Zend/Controller/Request/Abstract.php';
    23 require_once 'Zend/Controller/Request/Abstract.php';
    24 
    24 
   388      * @return Zend_Controller_Request_Http
   388      * @return Zend_Controller_Request_Http
   389      */
   389      */
   390     public function setRequestUri($requestUri = null)
   390     public function setRequestUri($requestUri = null)
   391     {
   391     {
   392         if ($requestUri === null) {
   392         if ($requestUri === null) {
   393             if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch
   393             if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) { 
       
   394                 // IIS with Microsoft Rewrite Module
       
   395                 $requestUri = $_SERVER['HTTP_X_ORIGINAL_URL'];
       
   396             } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) { 
       
   397                 // IIS with ISAPI_Rewrite
   394                 $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
   398                 $requestUri = $_SERVER['HTTP_X_REWRITE_URL'];
   395             } elseif (
   399             } elseif (
   396                 // IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
   400                 // IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
   397                 isset($_SERVER['IIS_WasUrlRewritten'])
   401                 isset($_SERVER['IIS_WasUrlRewritten'])
   398                 && $_SERVER['IIS_WasUrlRewritten'] == '1'
   402                 && $_SERVER['IIS_WasUrlRewritten'] == '1'
   543      * Everything in REQUEST_URI before PATH_INFO
   547      * Everything in REQUEST_URI before PATH_INFO
   544      * <form action="<?=$baseUrl?>/news/submit" method="POST"/>
   548      * <form action="<?=$baseUrl?>/news/submit" method="POST"/>
   545      *
   549      *
   546      * @return string
   550      * @return string
   547      */
   551      */
   548     public function getBaseUrl()
   552     public function getBaseUrl($raw = false)
   549     {
   553     {
   550         if (null === $this->_baseUrl) {
   554         if (null === $this->_baseUrl) {
   551             $this->setBaseUrl();
   555             $this->setBaseUrl();
   552         }
   556         }
   553 
   557 
   554         return urldecode($this->_baseUrl);
   558         return (($raw == false) ? urldecode($this->_baseUrl) : $this->_baseUrl);
   555     }
   559     }
   556 
   560 
   557     /**
   561     /**
   558      * Set the base path for the URL
   562      * Set the base path for the URL
   559      *
   563      *
   610      * @return Zend_Controller_Request_Http
   614      * @return Zend_Controller_Request_Http
   611      */
   615      */
   612     public function setPathInfo($pathInfo = null)
   616     public function setPathInfo($pathInfo = null)
   613     {
   617     {
   614         if ($pathInfo === null) {
   618         if ($pathInfo === null) {
   615             $baseUrl = $this->getBaseUrl();
   619             $baseUrl = $this->getBaseUrl(); // this actually calls setBaseUrl() & setRequestUri()
   616 
   620             $baseUrlRaw = $this->getBaseUrl(false);
       
   621             $baseUrlEncoded = urlencode($baseUrlRaw);
       
   622         
   617             if (null === ($requestUri = $this->getRequestUri())) {
   623             if (null === ($requestUri = $this->getRequestUri())) {
   618                 return $this;
   624                 return $this;
   619             }
   625             }
   620 
   626         
   621             // Remove the query string from REQUEST_URI
   627             // Remove the query string from REQUEST_URI
   622             if ($pos = strpos($requestUri, '?')) {
   628             if ($pos = strpos($requestUri, '?')) {
   623                 $requestUri = substr($requestUri, 0, $pos);
   629                 $requestUri = substr($requestUri, 0, $pos);
   624             }
   630             }
   625             
   631             
   626             $requestUri = urldecode($requestUri);
   632             if (!empty($baseUrl) || !empty($baseUrlRaw)) {
   627 
   633                 if (strpos($requestUri, $baseUrl) === 0) {
   628             if (null !== $baseUrl
   634                     $pathInfo = substr($requestUri, strlen($baseUrl));
   629                 && ((!empty($baseUrl) && 0 === strpos($requestUri, $baseUrl)) 
   635                 } elseif (strpos($requestUri, $baseUrlRaw) === 0) {
   630                     || empty($baseUrl))
   636                     $pathInfo = substr($requestUri, strlen($baseUrlRaw));
   631                     && false === ($pathInfo = substr($requestUri, strlen($baseUrl)))
   637                 } elseif (strpos($requestUri, $baseUrlEncoded) === 0) {
   632             ){ 
   638                     $pathInfo = substr($requestUri, strlen($baseUrlEncoded));
   633                 // If substr() returns false then PATH_INFO is set to an empty string 
   639                 } else {
   634                 $pathInfo = '';
   640                     $pathInfo = $requestUri;
   635             } elseif (null === $baseUrl 
   641                 }
   636                     || (!empty($baseUrl) && false === strpos($requestUri, $baseUrl))
   642             } else {
   637             ) { 
   643                 $pathInfo = $requestUri;
   638                 $pathInfo = $requestUri; 
   644             }
   639             }
   645         
   640         }
   646         }
   641 
   647 
   642         $this->_pathInfo = (string) $pathInfo;
   648         $this->_pathInfo = (string) $pathInfo;
   643         return $this;
   649         return $this;
   644     }
   650     }