ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
HTMLPurifier_URIParser Class Reference

Parses a URI into the components and fragment identifier as specified by RFC 3986. More...

+ Collaboration diagram for HTMLPurifier_URIParser:

Public Member Functions

 __construct ()
 
 parse ($uri)
 Parses a URI. More...
 

Protected Attributes

 $percentEncoder
 Instance of HTMLPurifier_PercentEncoder to do normalization with. More...
 

Detailed Description

Parses a URI into the components and fragment identifier as specified by RFC 3986.

Definition at line 7 of file URIParser.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_URIParser::__construct ( )

Definition at line 15 of file URIParser.php.

15  {
16  $this->percentEncoder = new HTMLPurifier_PercentEncoder();
17  }
Class that handles operations involving percent-encoding in URIs.

Member Function Documentation

◆ parse()

HTMLPurifier_URIParser::parse (   $uri)

Parses a URI.

Parameters
$uristring URI to parse
Returns
HTMLPurifier_URI representation of URI. This representation has not been validated yet and may not conform to RFC.

Definition at line 25 of file URIParser.php.

References $path, $query, and $result.

25  {
26 
27  $uri = $this->percentEncoder->normalize($uri);
28 
29  // Regexp is as per Appendix B.
30  // Note that ["<>] are an addition to the RFC's recommended
31  // characters, because they represent external delimeters.
32  $r_URI = '!'.
33  '(([^:/?#"<>]+):)?'. // 2. Scheme
34  '(//([^/?#"<>]*))?'. // 4. Authority
35  '([^?#"<>]*)'. // 5. Path
36  '(\?([^#"<>]*))?'. // 7. Query
37  '(#([^"<>]*))?'. // 8. Fragment
38  '!';
39 
40  $matches = array();
41  $result = preg_match($r_URI, $uri, $matches);
42 
43  if (!$result) return false; // *really* invalid URI
44 
45  // seperate out parts
46  $scheme = !empty($matches[1]) ? $matches[2] : null;
47  $authority = !empty($matches[3]) ? $matches[4] : null;
48  $path = $matches[5]; // always present, can be empty
49  $query = !empty($matches[6]) ? $matches[7] : null;
50  $fragment = !empty($matches[8]) ? $matches[9] : null;
51 
52  // further parse authority
53  if ($authority !== null) {
54  $r_authority = "/^((.+?)@)?(\[[^\]]+\]|[^:]*)(:(\d*))?/";
55  $matches = array();
56  preg_match($r_authority, $authority, $matches);
57  $userinfo = !empty($matches[1]) ? $matches[2] : null;
58  $host = !empty($matches[3]) ? $matches[3] : '';
59  $port = !empty($matches[4]) ? (int) $matches[5] : null;
60  } else {
61  $port = $host = $userinfo = null;
62  }
63 
64  return new HTMLPurifier_URI(
65  $scheme, $userinfo, $host, $port, $path, $query, $fragment);
66  }
$result
$path
Definition: index.php:22
HTML Purifier&#39;s internal representation of a URI.
Definition: URI.php:11

Field Documentation

◆ $percentEncoder

HTMLPurifier_URIParser::$percentEncoder
protected

Instance of HTMLPurifier_PercentEncoder to do normalization with.

Definition at line 13 of file URIParser.php.


The documentation for this class was generated from the following file: