121 'ihost' =>
'localhost'
149 public function __set($name, $value)
151 if (method_exists($this,
'set_' . $name))
153 call_user_func(array($this,
'set_' . $name), $value);
156 $name ===
'iauthority'
157 || $name ===
'iuserinfo'
160 || $name ===
'iquery'
161 || $name ===
'ifragment'
164 call_user_func(array($this,
'set_' . substr($name, 1)), $value);
178 $props = get_object_vars($this);
183 $name ===
'iauthority' ||
184 $name ===
'authority'
187 $return = $this->{
"get_$name"}();
189 elseif (array_key_exists($name, $props))
191 $return = $this->$name;
194 elseif (($prop =
'i' . $name) && array_key_exists($prop, $props))
197 $return = $this->$prop;
200 elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
203 $return = $this->$prop;
207 trigger_error(
'Undefined property: ' . get_class($this) .
'::' . $name, E_USER_NOTICE);
211 if ($return === null && isset($this->normalization[$this->scheme][$name]))
229 if (method_exists($this,
'get_' . $name) || isset($this->$name))
246 if (method_exists($this,
'set_' . $name))
248 call_user_func(array($this,
'set_' . $name),
'');
275 $relative =
new SimplePie_IRI($relative);
277 if (!$relative->is_valid())
281 elseif ($relative->scheme !== null)
283 return clone $relative;
287 if (!($base instanceof SimplePie_IRI))
289 $base =
new SimplePie_IRI($base);
291 if ($base->scheme !== null && $base->is_valid())
293 if ($relative->get_iri() !==
'')
295 if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
297 $target = clone $relative;
298 $target->scheme = $base->scheme;
302 $target =
new SimplePie_IRI;
303 $target->scheme = $base->scheme;
304 $target->iuserinfo = $base->iuserinfo;
305 $target->ihost = $base->ihost;
306 $target->port = $base->port;
307 if ($relative->ipath !==
'')
309 if ($relative->ipath[0] ===
'/')
311 $target->ipath = $relative->ipath;
313 elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath ===
'')
315 $target->ipath =
'/' . $relative->ipath;
317 elseif (($last_segment = strrpos($base->ipath,
'/')) !==
false)
319 $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
323 $target->ipath = $relative->ipath;
325 $target->ipath = $target->remove_dot_segments($target->ipath);
326 $target->iquery = $relative->iquery;
330 $target->ipath = $base->ipath;
331 if ($relative->iquery !== null)
333 $target->iquery = $relative->iquery;
335 elseif ($base->iquery !== null)
337 $target->iquery = $base->iquery;
340 $target->ifragment = $relative->ifragment;
345 $target = clone $base;
346 $target->ifragment = null;
348 $target->scheme_normalization();
366 $iri = trim($iri,
"\x20\x09\x0A\x0C\x0D");
367 if (preg_match(
'/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match))
369 if ($match[1] ===
'')
371 $match[
'scheme'] = null;
373 if (!isset($match[3]) || $match[3] ===
'')
375 $match[
'authority'] = null;
377 if (!isset($match[5]))
381 if (!isset($match[6]) || $match[6] ===
'')
383 $match[
'query'] = null;
385 if (!isset($match[8]) || $match[8] ===
'')
387 $match[
'fragment'] = null;
407 while (strpos($input,
'./') !==
false || strpos($input,
'/.') !==
false || $input ===
'.' || $input ===
'..')
410 if (strpos($input,
'../') === 0)
412 $input = substr($input, 3);
414 elseif (strpos($input,
'./') === 0)
416 $input = substr($input, 2);
419 elseif (strpos($input,
'/./') === 0)
421 $input = substr($input, 2);
423 elseif ($input ===
'/.')
428 elseif (strpos($input,
'/../') === 0)
430 $input = substr($input, 3);
431 $output = substr_replace($output,
'', strrpos($output,
'/'));
433 elseif ($input ===
'/..')
436 $output = substr_replace($output,
'', strrpos($output,
'/'));
439 elseif ($input ===
'.' || $input ===
'..')
444 elseif (($pos = strpos($input,
'/', 1)) !==
false)
446 $output .= substr($input, 0, $pos);
447 $input = substr_replace($input,
'', 0, $pos);
455 return $output . $input;
470 $string = preg_replace_callback(
'/(?:%[A-Fa-f0-9]{2})+/', array($this,
'remove_iunreserved_percent_encoded'), $string);
473 $string = preg_replace(
'/%(?![A-Fa-f0-9]{2})/',
'%25', $string);
477 $extra_chars .=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
481 $strlen = strlen($string);
482 while (($position += strspn($string, $extra_chars, $position)) < $strlen)
484 $value = ord($string[$position]);
494 if (($value & 0xE0) === 0xC0)
496 $character = ($value & 0x1F) << 6;
501 elseif (($value & 0xF0) === 0xE0)
503 $character = ($value & 0x0F) << 12;
508 elseif (($value & 0xF8) === 0xF0)
510 $character = ($value & 0x07) << 18;
524 if ($position + $length <= $strlen)
526 for ($position++; $remaining; $position++)
528 $value = ord($string[$position]);
531 if (($value & 0xC0) === 0x80)
533 $character |= ($value & 0x3F) << (--$remaining * 6);
546 $position = $strlen - 1;
556 || $length > 1 && $character <= 0x7F
557 || $length > 2 && $character <= 0x7FF
558 || $length > 3 && $character <= 0xFFFF
561 || ($character & 0xFFFE) === 0xFFFE
562 || $character >= 0xFDD0 && $character <= 0xFDEF
565 $character > 0xD7FF && $character < 0xF900
567 || $character > 0xEFFFD
572 || $character < 0xE000
573 || $character > 0x10FFFD
581 for ($j = $start; $j <= $position; $j++)
583 $string = substr_replace($string, sprintf(
'%%%02X', ord($string[$j])), $j, 1);
607 $bytes = explode(
'%', $match[0]);
616 for ($i = 1, $len = count($bytes); $i < $len; $i++)
618 $value = hexdec($bytes[$i]);
636 elseif (($value & 0xE0) === 0xC0)
638 $character = ($value & 0x1F) << 6;
643 elseif (($value & 0xF0) === 0xE0)
645 $character = ($value & 0x0F) << 12;
650 elseif (($value & 0xF8) === 0xF0)
652 $character = ($value & 0x07) << 18;
667 if (($value & 0xC0) === 0x80)
670 $character |= ($value & 0x3F) << ($remaining * 6);
689 || $length > 1 && $character <= 0x7F
690 || $length > 2 && $character <= 0x7FF
691 || $length > 3 && $character <= 0xFFFF
694 || $character > 0xEFFFD
696 || ($character & 0xFFFE) === 0xFFFE
697 || $character >= 0xFDD0 && $character <= 0xFDEF
699 || $character === 0x2F
700 || $character > 0x39 && $character < 0x41
701 || $character > 0x5A && $character < 0x61
702 || $character > 0x7A && $character < 0x7E
703 || $character > 0x7E && $character < 0xA0
704 || $character > 0xD7FF && $character < 0xF900
707 for ($j = $start; $j <= $i; $j++)
709 $string .=
'%' . strtoupper($bytes[$j]);
714 for ($j = $start; $j <= $i; $j++)
716 $string .= chr(hexdec($bytes[$j]));
726 for ($j = $start; $j < $len; $j++)
728 $string .=
'%' . strtoupper($bytes[$j]);
737 if (isset($this->normalization[$this->scheme][
'iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme][
'iuserinfo'])
739 $this->iuserinfo = null;
741 if (isset($this->normalization[$this->scheme][
'ihost']) && $this->ihost === $this->normalization[$this->scheme][
'ihost'])
745 if (isset($this->normalization[$this->scheme][
'port']) && $this->port === $this->normalization[$this->scheme][
'port'])
749 if (isset($this->normalization[$this->scheme][
'ipath']) && $this->ipath === $this->normalization[$this->scheme][
'ipath'])
753 if (isset($this->normalization[$this->scheme][
'iquery']) && $this->iquery === $this->normalization[$this->scheme][
'iquery'])
755 $this->iquery = null;
757 if (isset($this->normalization[$this->scheme][
'ifragment']) && $this->ifragment === $this->normalization[$this->scheme][
'ifragment'])
759 $this->ifragment = null;
771 $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
772 if ($this->ipath !==
'' &&
775 $this->ipath[0] !==
'/' ||
776 substr($this->ipath, 0, 2) ===
'//'
779 $this->scheme === null &&
781 strpos($this->ipath,
':') !==
false &&
782 (strpos($this->ipath,
'/') ===
false ?
true : strpos($this->ipath,
':') < strpos($this->ipath,
'/'))
812 elseif (isset($cache[$iri]))
821 $return) = $cache[$iri];
826 $parsed = $this->
parse_iri((
string) $iri);
832 $return = $this->
set_scheme($parsed[
'scheme'])
838 $cache[$iri] = array($this->scheme,
861 $this->scheme = null;
863 elseif (!preg_match(
'/^[A-Za-z][0-9A-Za-z+\-.]*$/',
$scheme))
865 $this->scheme = null;
870 $this->scheme = strtolower(
$scheme);
888 if ($authority === null)
890 $this->iuserinfo = null;
895 elseif (isset($cache[$authority]))
897 list($this->iuserinfo,
900 $return) = $cache[$authority];
906 $remaining = $authority;
907 if (($iuserinfo_end = strrpos($remaining,
'@')) !==
false)
909 $iuserinfo = substr($remaining, 0, $iuserinfo_end);
910 $remaining = substr($remaining, $iuserinfo_end + 1);
916 if (($port_start = strpos($remaining,
':', strpos($remaining,
']'))) !==
false)
918 if ((
$port = substr($remaining, $port_start + 1)) ===
false)
922 $remaining = substr($remaining, 0, $port_start);
933 $cache[$authority] = array($this->iuserinfo,
952 $this->iuserinfo = null;
977 elseif (substr(
$ihost, 0, 1) ===
'[' && substr(
$ihost, -1) ===
']')
998 while (($position += strcspn(
$ihost,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen)
1000 if (
$ihost[$position] ===
'%')
1033 elseif (strspn(
$port,
'0123456789') === strlen(
$port))
1035 $this->port = (int)
$port;
1062 if (isset($cache[
$ipath]))
1064 $this->ipath = $cache[
$ipath][(int) ($this->scheme !== null)];
1071 $cache[
$ipath] = array($valid, $removed);
1072 $this->ipath = ($this->scheme !== null) ? $removed : $valid;
1089 $this->iquery = null;
1109 $this->ifragment = null;
1129 $non_ascii = implode(
'', range(
"\x80",
"\xFF"));
1133 $strlen = strlen($string);
1134 while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
1136 $string = substr_replace($string, sprintf(
'%%%02X', ord($string[$position])), $position, 1);
1157 if ($this->scheme !== null)
1159 $iri .= $this->scheme .
':';
1163 $iri .=
'//' . $iauthority;
1165 if ($this->ipath !==
'')
1169 elseif (!empty($this->normalization[$this->scheme][
'ipath']) && $iauthority !== null && $iauthority !==
'')
1173 if ($this->iquery !== null)
1177 if ($this->ifragment !== null)
1202 if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null)
1205 if ($this->iuserinfo !== null)
1207 $iauthority .= $this->iuserinfo .
'@';
1209 if ($this->ihost !== null)
1213 if ($this->port !== null)
1233 if (is_string($iauthority))
1234 return $this->
to_uri($iauthority);