wp/wp-includes/Requests/IRI.php
changeset 18 be944660c56a
parent 7 cf61fcea0001
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    65  */
    65  */
    66 class Requests_IRI {
    66 class Requests_IRI {
    67 	/**
    67 	/**
    68 	 * Scheme
    68 	 * Scheme
    69 	 *
    69 	 *
       
    70 	 * @var string|null
       
    71 	 */
       
    72 	protected $scheme = null;
       
    73 
       
    74 	/**
       
    75 	 * User Information
       
    76 	 *
       
    77 	 * @var string|null
       
    78 	 */
       
    79 	protected $iuserinfo = null;
       
    80 
       
    81 	/**
       
    82 	 * ihost
       
    83 	 *
       
    84 	 * @var string|null
       
    85 	 */
       
    86 	protected $ihost = null;
       
    87 
       
    88 	/**
       
    89 	 * Port
       
    90 	 *
       
    91 	 * @var string|null
       
    92 	 */
       
    93 	protected $port = null;
       
    94 
       
    95 	/**
       
    96 	 * ipath
       
    97 	 *
    70 	 * @var string
    98 	 * @var string
    71 	 */
    99 	 */
    72 	protected $scheme = null;
       
    73 
       
    74 	/**
       
    75 	 * User Information
       
    76 	 *
       
    77 	 * @var string
       
    78 	 */
       
    79 	protected $iuserinfo = null;
       
    80 
       
    81 	/**
       
    82 	 * ihost
       
    83 	 *
       
    84 	 * @var string
       
    85 	 */
       
    86 	protected $ihost = null;
       
    87 
       
    88 	/**
       
    89 	 * Port
       
    90 	 *
       
    91 	 * @var string
       
    92 	 */
       
    93 	protected $port = null;
       
    94 
       
    95 	/**
       
    96 	 * ipath
       
    97 	 *
       
    98 	 * @var string
       
    99 	 */
       
   100 	protected $ipath = '';
   100 	protected $ipath = '';
   101 
   101 
   102 	/**
   102 	/**
   103 	 * iquery
   103 	 * iquery
   104 	 *
   104 	 *
   105 	 * @var string
   105 	 * @var string|null
   106 	 */
   106 	 */
   107 	protected $iquery = null;
   107 	protected $iquery = null;
   108 
   108 
   109 	/**
   109 	/**
   110 	 * ifragment
   110 	 * ifragment|null
   111 	 *
   111 	 *
   112 	 * @var string
   112 	 * @var string
   113 	 */
   113 	 */
   114 	protected $ifragment = null;
   114 	protected $ifragment = null;
   115 
   115 
   116 	/**
   116 	/**
   117 	 * Normalization database
   117 	 * Normalization database
   118 	 *
   118 	 *
   119 	 * Each key is the scheme, each value is an array with each key as the IRI
   119 	 * Each key is the scheme, each value is an array with each key as the IRI
   120 	 * part and value as the default value for that part.
   120 	 * part and value as the default value for that part.
       
   121 	 *
       
   122 	 * @var array
   121 	 */
   123 	 */
   122 	protected $normalization = array(
   124 	protected $normalization = array(
   123 		'acap' => array(
   125 		'acap' => array(
   124 			'port' => 674
   126 			'port' => 674
   125 		),
   127 		),
   247 	/**
   249 	/**
   248 	 * Create a new IRI object by resolving a relative IRI
   250 	 * Create a new IRI object by resolving a relative IRI
   249 	 *
   251 	 *
   250 	 * Returns false if $base is not absolute, otherwise an IRI.
   252 	 * Returns false if $base is not absolute, otherwise an IRI.
   251 	 *
   253 	 *
   252 	 * @param IRI|string $base (Absolute) Base IRI
   254 	 * @param Requests_IRI|string $base (Absolute) Base IRI
   253 	 * @param IRI|string $relative Relative IRI
   255 	 * @param Requests_IRI|string $relative Relative IRI
   254 	 * @return IRI|false
   256 	 * @return Requests_IRI|false
   255 	 */
   257 	 */
   256 	public static function absolutize($base, $relative) {
   258 	public static function absolutize($base, $relative) {
   257 		if (!($relative instanceof Requests_IRI)) {
   259 		if (!($relative instanceof Requests_IRI)) {
   258 			$relative = new Requests_IRI($relative);
   260 			$relative = new Requests_IRI($relative);
   259 		}
   261 		}
   417 	 * @param bool $iprivate Allow iprivate
   419 	 * @param bool $iprivate Allow iprivate
   418 	 * @return string
   420 	 * @return string
   419 	 */
   421 	 */
   420 	protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) {
   422 	protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) {
   421 		// Normalize as many pct-encoded sections as possible
   423 		// Normalize as many pct-encoded sections as possible
   422 		$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array(&$this, 'remove_iunreserved_percent_encoded'), $string);
   424 		$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
   423 
   425 
   424 		// Replace invalid percent characters
   426 		// Replace invalid percent characters
   425 		$string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
   427 		$string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
   426 
   428 
   427 		// Add unreserved and % to $extra_chars (the latter is safe because all
   429 		// Add unreserved and % to $extra_chars (the latter is safe because all
  1008 	}
  1010 	}
  1009 
  1011 
  1010 	/**
  1012 	/**
  1011 	 * Get the complete IRI
  1013 	 * Get the complete IRI
  1012 	 *
  1014 	 *
  1013 	 * @return string
  1015 	 * @return string|false
  1014 	 */
  1016 	 */
  1015 	protected function get_iri() {
  1017 	protected function get_iri() {
  1016 		if (!$this->is_valid()) {
  1018 		if (!$this->is_valid()) {
  1017 			return false;
  1019 			return false;
  1018 		}
  1020 		}
  1045 	}
  1047 	}
  1046 
  1048 
  1047 	/**
  1049 	/**
  1048 	 * Get the complete iauthority
  1050 	 * Get the complete iauthority
  1049 	 *
  1051 	 *
  1050 	 * @return string
  1052 	 * @return string|null
  1051 	 */
  1053 	 */
  1052 	protected function get_iauthority() {
  1054 	protected function get_iauthority() {
  1053 		if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) {
  1055 		if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) {
  1054 			return null;
  1056 			return null;
  1055 		}
  1057 		}