00001 <?php 00032 class Zend_View_Helper_ServerUrl 00033 { 00039 protected $_scheme; 00040 00046 protected $_host; 00047 00053 public function __construct() 00054 { 00055 if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)) { 00056 $scheme = 'https'; 00057 } else { 00058 $scheme = 'http'; 00059 } 00060 $this->setScheme($scheme); 00061 00062 if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) { 00063 $this->setHost($_SERVER['HTTP_HOST']); 00064 } else if (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) { 00065 $name = $_SERVER['SERVER_NAME']; 00066 $port = $_SERVER['SERVER_PORT']; 00067 00068 if (($scheme == 'http' && $port == 80) || 00069 ($scheme == 'https' && $port == 443)) { 00070 $this->setHost($name); 00071 } else { 00072 $this->setHost($name . ':' . $port); 00073 } 00074 } 00075 } 00076 00088 public function serverUrl($requestUri = null) 00089 { 00090 if ($requestUri === true) { 00091 $path = $_SERVER['REQUEST_URI']; 00092 } else if (is_string($requestUri)) { 00093 $path = $requestUri; 00094 } else { 00095 $path = ''; 00096 } 00097 00098 return $this->getScheme() . '://' . $this->getHost() . $path; 00099 } 00100 00106 public function getHost() 00107 { 00108 return $this->_host; 00109 } 00110 00117 public function setHost($host) 00118 { 00119 $this->_host = $host; 00120 return $this; 00121 } 00122 00128 public function getScheme() 00129 { 00130 return $this->_scheme; 00131 } 00132 00139 public function setScheme($scheme) 00140 { 00141 $this->_scheme = $scheme; 00142 return $this; 00143 } 00144 }