Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00018 class Url extends GenericUri
00019 {
00020 protected $knownSubSchemes = array(
00021 'http' => 'HttpUrl',
00022 'https' => 'HttpUrl',
00023 'ftp' => 'Url',
00024 'nntp' => 'Url',
00025 'telnet' => 'Url',
00026 'gopher' => 'Url',
00027 'wais' => 'Url',
00028 'file' => 'Url',
00029 'prospero' => 'Url'
00030 );
00031
00035 public static function create()
00036 {
00037 return new self;
00038 }
00039
00040 public function getKnownSubSchemes()
00041 {
00042 return $this->knownSubSchemes;
00043 }
00044
00045 public function isValid()
00046 {
00047 if (!parent::isValid())
00048 return false;
00049
00050 return
00051 ($this->isAbsolute() && $this->getAuthority() !== null)
00052 || ($this->isRelative() && $this->getAuthority() === null);
00053 }
00054
00060 public function fixAuthorityFromPath()
00061 {
00062 if ($this->scheme && !$this->getAuthority()) {
00063 $segments = explode('/', $this->path);
00064
00065 while ($segments && empty($segments[0]))
00066 array_shift($segments);
00067
00068 if ($segments) {
00069 $this->setAuthority(array_shift($segments));
00070 $this->setPath('/'.implode('/', $segments));
00071 }
00072 }
00073
00074 return $this;
00075 }
00076
00080 public function fixMistakenPath()
00081 {
00082 if ($this->scheme || $this->getAuthority())
00083 return $this;
00084
00085 $urlSubSchemes = Url::create()->getKnownSubSchemes();
00086
00087 $matches = array();
00088
00089 if (
00090 !preg_match('/^([a-z][a-z0-9.+-]*):(.*)/i', $this->path, $matches)
00091 || !isset($urlSubSchemes[strtolower($matches[1])])
00092 ) {
00093
00094 return $this;
00095 }
00096
00097
00098
00099
00100 $this->setScheme($matches[1]);
00101 $this->setPath($matches[2]);
00102
00103 $this->fixAuthorityFromPath();
00104
00105 return $this;
00106 }
00107
00108 public function toSmallString()
00109 {
00110 $result = null;
00111
00112 $authority = $this->getAuthority();
00113
00114 if ($authority !== null)
00115 $result .= $authority;
00116
00117 $result .= $this->path;
00118
00119 if ($this->query !== null)
00120 $result .= '?'.$this->query;
00121
00122 if ($this->fragment !== null)
00123 $result .= '#'.$this->fragment;
00124
00125 return $result;
00126 }
00127
00128 public function normalize()
00129 {
00130 parent::normalize();
00131
00132 if ($this->getPort() === '')
00133 $this->setPort(null);
00134
00135 return $this;
00136 }
00137 }
00138 ?>