00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class HttpUrl extends Url
00017 {
00018 protected $knownSubSchemes = array();
00019
00023 public static function create()
00024 {
00025 return new self;
00026 }
00027
00028 public function ensureAbsolute()
00029 {
00030 $this->fixMistakenPath();
00031
00032 if (!$this->scheme && !$this->getAuthority()) {
00033 $this->scheme = 'http';
00034
00035 $segments = explode('/', $this->path);
00036
00037 if (!empty($segments[0])) {
00038
00039
00040 $this->setAuthority(array_shift($segments));
00041
00042 $this->setPath('/'.implode('/', $segments));
00043 }
00044 }
00045
00046 $this->fixAuthorityFromPath();
00047
00048 return $this;
00049 }
00050
00051 public function isValidScheme()
00052 {
00053 if (!parent::isValidScheme())
00054 return false;
00055
00056 if (
00057 $this->scheme
00058 && !in_array(strtolower($this->scheme), array('http', 'https'))
00059 )
00060 return false;
00061
00062 return true;
00063 }
00064
00065 public function isValidPort()
00066 {
00067 if (!parent::isValidPort())
00068 return false;
00069
00070 if (
00071 $this->port
00072 && !in_array($this->port, array(80, 443))
00073 && $this->port < 1024
00074 )
00075 return false;
00076
00077 return true;
00078 }
00079
00080 protected function isValidHostName()
00081 {
00082 if (!parent::isValidHostName())
00083 return false;
00084
00085 $charPattern = $this->charPattern(null);
00086
00087
00088
00089
00090 $topLabelPattern = '(([a-z])|([a-z]([a-z0-9-])*[a-z0-9]))\.?';
00091
00092 return (
00093 preg_match(
00094 "/^($charPattern*\.)?{$topLabelPattern}$/i",
00095 $this->host
00096 ) == 1
00097 );
00098 }
00099
00100 public function normalize()
00101 {
00102 parent::normalize();
00103
00104 $port = $this->getPort();
00105 $scheme = $this->getScheme();
00106
00107 if (
00108 ($scheme == 'http' && $port == '80')
00109 || ($scheme == 'https' && $port == '443')
00110 )
00111 $this->setPort(null);
00112
00113 if ($this->getPath() === null || $this->getPath() === '')
00114 $this->setPath('/');
00115
00116 return $this;
00117 }
00118
00119 public function makeComparable()
00120 {
00121 return $this->ensureAbsolute()->normalize()->setFragment(null);
00122 }
00123 }
00124 ?>