ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ILIAS\Data\URI Class Reference

The scope of this class is split ilias-conform URI's into components. More...

+ Collaboration diagram for ILIAS\Data\URI:

Public Member Functions

 __construct (string $uri_string)
 
 schema ()
 
 withSchema (string $schema)
 Get URI with modified schema. More...
 
 authority ()
 
 withAuthority (string $authority)
 Get URI with modified authority. More...
 
 port ()
 
 withPort (int $port=null)
 Get URI with modified port. More...
 
 host ()
 
 withHost (string $host)
 Get URI with modified host. More...
 
 path ()
 
 withPath (string $path=null)
 Get URI with modified path. More...
 
 query ()
 
 withQuery (string $query=null)
 Get URI with modified query. More...
 
 fragment ()
 
 withFragment (string $fragment=null)
 Get URI with modified fragment. More...
 
 baseURI ()
 Get a well-formed URI consisting only out of schema, authority and port. More...
 

Data Fields

const PATH_DELIM = '/'
 
const ALPHA = '[A-Za-z]'
 Relevant character-groups as defined in RFC 3986 Appendix 1. More...
 
const DIGIT = '[0-9]'
 
const ALPHA_DIGIT = '[A-Za-z0-9]'
 
const HEXDIG = '[0-9A-Fa-f]'
 
const PCTENCODED = '%' . self::HEXDIG . self::HEXDIG
 
const PIMP = '[\\+\\-\\.]'
 point|minus|plus to be used in schema. More...
 
const SUBDELIMS = '[\\$,;=!&\'\\‍(\\‍)\\*\\+]'
 valid subdelims according to RFC 3986 Appendix 1: "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "=" More...
 
const BASEURI_SUBDELIMS = '[\\$,;&\'\\*]'
 subdelims without jsf**k characters +!() and = More...
 
const UNRESERVED = self::ALPHA_DIGIT . '|[\\-\\._~]'
 
const UNRESERVED_NO_DOT = self::ALPHA_DIGIT . '|[\\-_~]'
 
const PCHAR = self::UNRESERVED . '|' . self::SUBDELIMS . '|' . self::PCTENCODED . '|:|@'
 
const BASEURI_PCHAR = self::UNRESERVED . '|' . self::BASEURI_SUBDELIMS . '|' . self::PCTENCODED . '|:|@'
 
const SCHEMA = '#^' . self::ALPHA . '(' . self::ALPHA_DIGIT . '|' . self::PIMP . ')*$#'
 
const DOMAIN_LABEL = self::ALPHA_DIGIT . '((' . self::UNRESERVED_NO_DOT . '|' . self::PCTENCODED . '|' . self::BASEURI_SUBDELIMS . ')*' . self::ALPHA_DIGIT . ')*'
 
const HOST_REG_NAME = '^' . self::DOMAIN_LABEL . '(\\.' . self::DOMAIN_LABEL . ')*$'
 
const HOST_IPV4 = '^(' . self::DIGIT . '{1,3})(\\.' . self::DIGIT . '{1,3}){3}$'
 
const HOST = '#' . self::HOST_IPV4 . '|' . self::HOST_REG_NAME . '#'
 
const PORT = '#^' . self::DIGIT . '+$#'
 
const PATH = '#^(?!//)(?!:)(' . self::PCHAR . '|' . self::PATH_DELIM . ')+$#'
 
const QUERY = '#^(' . self::PCHAR . '|' . self::PATH_DELIM . '|\\?)+$#'
 
const FRAGMENT = '#^(' . self::PCHAR . '|' . self::PATH_DELIM . '|\\?|\\#)+$#'
 

Protected Member Functions

 digestSchema (string $schema)
 Check schema formating. More...
 
 digestHost (string $host)
 Check host formating. More...
 
 digestPort (int $port=null)
 Check port formating. More...
 
 digestPath (string $path=null)
 Check path formating. More...
 
 digestQuery (string $query=null)
 Check query formating. More...
 
 digestFragment (string $fragment=null)
 Check fragment formating. More...
 
 checkCorrectFormatOrThrow (string $regexp, string $string)
 Check wether a string fits a regexp. More...
 

Protected Attributes

 $schema
 
 $host
 
 $port
 
 $path
 
 $query
 
 $fragment
 

Detailed Description

The scope of this class is split ilias-conform URI's into components.

Please refer to RFC 3986 for details. Notice, ilias-confor URI's will form a SUBSET of RFC 3986:

  • Notice the restrictions on baseuri-subdelims.
  • We require a schema and an authority to be present.
  • If any part is located and it is invalid an exception will be thrown instead of just omiting it.
    • IPv6 is currently not supported.

Definition at line 17 of file URI.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Data\URI::__construct ( string  $uri_string)

Definition at line 85 of file URI.php.

86 {
87 $this->schema = $this->digestSchema(parse_url($uri_string, PHP_URL_SCHEME));
88 $this->host = $this->digestHost(parse_url($uri_string, PHP_URL_HOST));
89 $this->port = $this->digestPort(parse_url($uri_string, PHP_URL_PORT));
90 $this->path = $this->digestPath(parse_url($uri_string, PHP_URL_PATH));
91 $this->query = $this->digestQuery(parse_url($uri_string, PHP_URL_QUERY));
92 $this->fragment = $this->digestFragment(parse_url($uri_string, PHP_URL_FRAGMENT));
93 }
digestPath(string $path=null)
Check path formating.
Definition: URI.php:140
digestPort(int $port=null)
Check port formating.
Definition: URI.php:125
digestHost(string $host)
Check host formating.
Definition: URI.php:114
digestFragment(string $fragment=null)
Check fragment formating.
Definition: URI.php:174
digestSchema(string $schema)
Check schema formating.
Definition: URI.php:102
digestQuery(string $query=null)
Check query formating.
Definition: URI.php:159

References ILIAS\Data\URI\digestFragment(), ILIAS\Data\URI\digestHost(), ILIAS\Data\URI\digestPath(), ILIAS\Data\URI\digestPort(), ILIAS\Data\URI\digestQuery(), ILIAS\Data\URI\digestSchema(), ILIAS\Data\URI\fragment(), ILIAS\Data\URI\host(), ILIAS\Data\URI\path(), ILIAS\Data\URI\port(), ILIAS\Data\URI\query(), and ILIAS\Data\URI\schema().

+ Here is the call graph for this function:

Member Function Documentation

◆ authority()

ILIAS\Data\URI::authority ( )
Returns
string

Definition at line 226 of file URI.php.

226 : string
227 {
228 $port = $this->port();
229 if ($port === null) {
230 return $this->host();
231 }
232 return $this->host() . ':' . $port;
233 }

References ILIAS\Data\URI\$port, ILIAS\Data\URI\host(), and ILIAS\Data\URI\port().

Referenced by ILIAS\Data\URI\baseURI().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ baseURI()

ILIAS\Data\URI::baseURI ( )

Get a well-formed URI consisting only out of schema, authority and port.

Returns
string

Definition at line 376 of file URI.php.

376 : string
377 {
378 $path = $this->path();
379 if ($path === null) {
380 return $this->schema() . '://' . $this->authority();
381 }
382 return $this->schema() . '://' . $this->authority() . '/' . $path;
383 }

References ILIAS\Data\URI\$path, ILIAS\Data\URI\authority(), ILIAS\Data\URI\path(), and ILIAS\Data\URI\schema().

+ Here is the call graph for this function:

◆ checkCorrectFormatOrThrow()

ILIAS\Data\URI::checkCorrectFormatOrThrow ( string  $regexp,
string  $string 
)
protected

Check wether a string fits a regexp.

Return it, if so, throw otherwise.

Parameters
string$regexp
string$string
Exceptions

InvalidArgumentException

Returns
string|null

Definition at line 192 of file URI.php.

193 {
194 if (preg_match($regexp, (string) $string) === 1) {
195 return $string;
196 }
197 throw new \InvalidArgumentException('ill-formated component "' . $string . '" expected "' . $regexp . '"');
198 }

Referenced by ILIAS\Data\URI\digestFragment(), ILIAS\Data\URI\digestHost(), ILIAS\Data\URI\digestPath(), ILIAS\Data\URI\digestQuery(), ILIAS\Data\URI\digestSchema(), and ILIAS\Data\URI\withAuthority().

+ Here is the caller graph for this function:

◆ digestFragment()

ILIAS\Data\URI::digestFragment ( string  $fragment = null)
protected

Check fragment formating.

Return it in case of success.

Parameters
string | null$fragment
Exceptions

InvalidArgumentException

Returns
string|null

Definition at line 174 of file URI.php.

175 {
176 if ($fragment === null) {
177 return null;
178 }
179 return $this->checkCorrectFormatOrThrow(self::FRAGMENT, $fragment);
180 }
checkCorrectFormatOrThrow(string $regexp, string $string)
Check wether a string fits a regexp.
Definition: URI.php:192

References ILIAS\Data\URI\$fragment, and ILIAS\Data\URI\checkCorrectFormatOrThrow().

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\withFragment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ digestHost()

ILIAS\Data\URI::digestHost ( string  $host)
protected

Check host formating.

Return it in case of success.

Parameters
string$host
Exceptions

InvalidArgumentException

Returns
string

Definition at line 114 of file URI.php.

114 : string
115 {
116 return $this->checkCorrectFormatOrThrow(self::HOST, (string) $host);
117 }

References ILIAS\Data\URI\$host, and ILIAS\Data\URI\checkCorrectFormatOrThrow().

Referenced by ILIAS\Data\URI\__construct(), ILIAS\Data\URI\withAuthority(), and ILIAS\Data\URI\withHost().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ digestPath()

ILIAS\Data\URI::digestPath ( string  $path = null)
protected

Check path formating.

Return it in case of success.

Parameters
string | null$path
Exceptions

InvalidArgumentException

Returns
string|null

Definition at line 140 of file URI.php.

141 {
142 if ($path === null) {
143 return null;
144 }
145 $path = trim($this->checkCorrectFormatOrThrow(self::PATH, $path), self::PATH_DELIM);
146 if ($path === '') {
147 $path = null;
148 }
149 return $path;
150 }
const PATH
Definition: proxy_ylocal.php:8

References ILIAS\Data\URI\$path, ILIAS\Data\URI\checkCorrectFormatOrThrow(), and PATH.

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\withPath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ digestPort()

ILIAS\Data\URI::digestPort ( int  $port = null)
protected

Check port formating.

Return it in case of success.

Parameters
int | null$port
Returns
int|null

Definition at line 125 of file URI.php.

126 {
127 if ($port === null) {
128 return null;
129 }
130 return $port;
131 }

References ILIAS\Data\URI\$port.

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\withPort().

+ Here is the caller graph for this function:

◆ digestQuery()

ILIAS\Data\URI::digestQuery ( string  $query = null)
protected

Check query formating.

Return it in case of success.

Parameters
string | null$query
Exceptions

InvalidArgumentException

Returns
string|null

Definition at line 159 of file URI.php.

160 {
161 if ($query === null) {
162 return null;
163 }
164 return $this->checkCorrectFormatOrThrow(self::QUERY, $query);
165 }

References ILIAS\Data\URI\$query, and ILIAS\Data\URI\checkCorrectFormatOrThrow().

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\withQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ digestSchema()

ILIAS\Data\URI::digestSchema ( string  $schema)
protected

Check schema formating.

Return it in case of success.

Parameters
string$schema
Exceptions

InvalidArgumentException

Returns
string

Definition at line 102 of file URI.php.

102 : string
103 {
104 return $this->checkCorrectFormatOrThrow(self::SCHEMA, (string) $schema);
105 }

References ILIAS\Data\URI\$schema, and ILIAS\Data\URI\checkCorrectFormatOrThrow().

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\withSchema().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fragment()

ILIAS\Data\URI::fragment ( )
Returns
string|null

Definition at line 351 of file URI.php.

352 {
353 return $this->fragment;
354 }

References ILIAS\Data\URI\$fragment.

Referenced by ILIAS\Data\URI\__construct().

+ Here is the caller graph for this function:

◆ host()

ILIAS\Data\URI::host ( )
Returns
string

Definition at line 284 of file URI.php.

284 : string
285 {
286 return $this->host;
287 }

References ILIAS\Data\URI\$host.

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\authority().

+ Here is the caller graph for this function:

◆ path()

ILIAS\Data\URI::path ( )
Returns
string|null

Definition at line 307 of file URI.php.

308 {
309 return $this->path;
310 }

References ILIAS\Data\URI\$path.

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\baseURI().

+ Here is the caller graph for this function:

◆ port()

ILIAS\Data\URI::port ( )
Returns
int|null

Definition at line 262 of file URI.php.

263 {
264 return $this->port;
265 }

References ILIAS\Data\URI\$port.

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\authority().

+ Here is the caller graph for this function:

◆ query()

ILIAS\Data\URI::query ( )
Returns
string|null

Definition at line 329 of file URI.php.

330 {
331 return $this->query;
332 }

References ILIAS\Data\URI\$query.

Referenced by ILIAS\Data\URI\__construct().

+ Here is the caller graph for this function:

◆ schema()

ILIAS\Data\URI::schema ( )
Returns
string

Definition at line 203 of file URI.php.

203 : string
204 {
205 return $this->schema;
206 }

References ILIAS\Data\URI\$schema.

Referenced by ILIAS\Data\URI\__construct(), and ILIAS\Data\URI\baseURI().

+ Here is the caller graph for this function:

◆ withAuthority()

ILIAS\Data\URI::withAuthority ( string  $authority)

Get URI with modified authority.

Parameters
string$authority
Returns
URI

Definition at line 242 of file URI.php.

242 : URI
243 {
244 $parts = explode(':', $authority);
245 if (count($parts) > 2) {
246 throw new \InvalidArgumentException('ill-formated component ' . $authority);
247 }
248 $host = $this->digestHost($parts[0]);
249 $port = null;
250 if (array_key_exists(1, $parts)) {
251 $port = (int) $this->checkCorrectFormatOrThrow(self::PORT, (string) $parts[1]);
252 }
253 $other = clone $this;
254 $other->host = $host;
255 $other->port = $port;
256 return $other;
257 }
$authority

References $authority, ILIAS\Data\URI\$host, ILIAS\Data\URI\$port, ILIAS\Data\URI\checkCorrectFormatOrThrow(), and ILIAS\Data\URI\digestHost().

+ Here is the call graph for this function:

◆ withFragment()

ILIAS\Data\URI::withFragment ( string  $fragment = null)

Get URI with modified fragment.

Parameters
string | null$fragment
Returns
URI

Definition at line 362 of file URI.php.

362 : URI
363 {
365 $other = clone $this;
366 $other->fragment = $fragment;
367 return $other;
368 }

References ILIAS\Data\URI\$fragment, and ILIAS\Data\URI\digestFragment().

+ Here is the call graph for this function:

◆ withHost()

ILIAS\Data\URI::withHost ( string  $host)

Get URI with modified host.

Parameters
string$host
Returns
URI

Definition at line 295 of file URI.php.

295 : URI
296 {
297 $host = $this->digestHost($host);
298 $other = clone $this;
299 $other->host = $host;
300 return $other;
301 }

References ILIAS\Data\URI\$host, and ILIAS\Data\URI\digestHost().

+ Here is the call graph for this function:

◆ withPath()

ILIAS\Data\URI::withPath ( string  $path = null)

Get URI with modified path.

Parameters
string | null$path
Returns
URI

Definition at line 318 of file URI.php.

318 : URI
319 {
320 $path = $this->digestPath($path);
321 $other = clone $this;
322 $other->path = $path;
323 return $other;
324 }

References ILIAS\Data\URI\$path, and ILIAS\Data\URI\digestPath().

+ Here is the call graph for this function:

◆ withPort()

ILIAS\Data\URI::withPort ( int  $port = null)

Get URI with modified port.

Parameters
int | null$port
Returns
URI

Definition at line 273 of file URI.php.

273 : URI
274 {
275 $port = $this->digestPort($port);
276 $other = clone $this;
277 $other->port = $port;
278 return $other;
279 }

References ILIAS\Data\URI\$port, and ILIAS\Data\URI\digestPort().

+ Here is the call graph for this function:

◆ withQuery()

ILIAS\Data\URI::withQuery ( string  $query = null)

Get URI with modified query.

Parameters
string | null$query
Returns
URI

Definition at line 340 of file URI.php.

340 : URI
341 {
342 $query = $this->digestQuery($query);
343 $other = clone $this;
344 $other->query = $query;
345 return $other;
346 }

References ILIAS\Data\URI\$query, and ILIAS\Data\URI\digestQuery().

+ Here is the call graph for this function:

◆ withSchema()

ILIAS\Data\URI::withSchema ( string  $schema)

Get URI with modified schema.

Parameters
string$schema
Returns
URI

Definition at line 214 of file URI.php.

214 : URI
215 {
216 $shema = $this->digestSchema($schema);
217 $other = clone $this;
218 $other->schema = $schema;
219 return $other;
220 }

References ILIAS\Data\URI\$schema, and ILIAS\Data\URI\digestSchema().

+ Here is the call graph for this function:

Field Documentation

◆ $fragment

ILIAS\Data\URI::$fragment
protected

◆ $host

ILIAS\Data\URI::$host
protected

◆ $path

ILIAS\Data\URI::$path
protected

◆ $port

◆ $query

ILIAS\Data\URI::$query
protected

◆ $schema

ILIAS\Data\URI::$schema
protected

◆ ALPHA

const ILIAS\Data\URI::ALPHA = '[A-Za-z]'

Relevant character-groups as defined in RFC 3986 Appendix 1.

Definition at line 49 of file URI.php.

◆ ALPHA_DIGIT

const ILIAS\Data\URI::ALPHA_DIGIT = '[A-Za-z0-9]'

Definition at line 51 of file URI.php.

◆ BASEURI_PCHAR

const ILIAS\Data\URI::BASEURI_PCHAR = self::UNRESERVED . '|' . self::BASEURI_SUBDELIMS . '|' . self::PCTENCODED . '|:|@'

Definition at line 73 of file URI.php.

◆ BASEURI_SUBDELIMS

const ILIAS\Data\URI::BASEURI_SUBDELIMS = '[\\$,;&\'\\*]'

subdelims without jsf**k characters +!() and =

Definition at line 67 of file URI.php.

◆ DIGIT

const ILIAS\Data\URI::DIGIT = '[0-9]'

Definition at line 50 of file URI.php.

◆ DOMAIN_LABEL

const ILIAS\Data\URI::DOMAIN_LABEL = self::ALPHA_DIGIT . '((' . self::UNRESERVED_NO_DOT . '|' . self::PCTENCODED . '|' . self::BASEURI_SUBDELIMS . ')*' . self::ALPHA_DIGIT . ')*'

Definition at line 76 of file URI.php.

◆ FRAGMENT

const ILIAS\Data\URI::FRAGMENT = '#^(' . self::PCHAR . '|' . self::PATH_DELIM . '|\\?|\\#)+$#'

Definition at line 83 of file URI.php.

◆ HEXDIG

const ILIAS\Data\URI::HEXDIG = '[0-9A-Fa-f]'

Definition at line 52 of file URI.php.

◆ HOST

const ILIAS\Data\URI::HOST = '#' . self::HOST_IPV4 . '|' . self::HOST_REG_NAME . '#'

Definition at line 79 of file URI.php.

◆ HOST_IPV4

const ILIAS\Data\URI::HOST_IPV4 = '^(' . self::DIGIT . '{1,3})(\\.' . self::DIGIT . '{1,3}){3}$'

Definition at line 78 of file URI.php.

◆ HOST_REG_NAME

const ILIAS\Data\URI::HOST_REG_NAME = '^' . self::DOMAIN_LABEL . '(\\.' . self::DOMAIN_LABEL . ')*$'

Definition at line 77 of file URI.php.

◆ PATH

const ILIAS\Data\URI::PATH = '#^(?!//)(?!:)(' . self::PCHAR . '|' . self::PATH_DELIM . ')+$#'

Definition at line 81 of file URI.php.

◆ PATH_DELIM

const ILIAS\Data\URI::PATH_DELIM = '/'

Definition at line 44 of file URI.php.

◆ PCHAR

const ILIAS\Data\URI::PCHAR = self::UNRESERVED . '|' . self::SUBDELIMS . '|' . self::PCTENCODED . '|:|@'

Definition at line 72 of file URI.php.

◆ PCTENCODED

const ILIAS\Data\URI::PCTENCODED = '%' . self::HEXDIG . self::HEXDIG

Definition at line 53 of file URI.php.

◆ PIMP

const ILIAS\Data\URI::PIMP = '[\\+\\-\\.]'

point|minus|plus to be used in schema.

Definition at line 57 of file URI.php.

◆ PORT

const ILIAS\Data\URI::PORT = '#^' . self::DIGIT . '+$#'

Definition at line 80 of file URI.php.

◆ QUERY

const ILIAS\Data\URI::QUERY = '#^(' . self::PCHAR . '|' . self::PATH_DELIM . '|\\?)+$#'

Definition at line 82 of file URI.php.

◆ SCHEMA

const ILIAS\Data\URI::SCHEMA = '#^' . self::ALPHA . '(' . self::ALPHA_DIGIT . '|' . self::PIMP . ')*$#'

Definition at line 75 of file URI.php.

◆ SUBDELIMS

const ILIAS\Data\URI::SUBDELIMS = '[\\$,;=!&\'\\‍(\\‍)\\*\\+]'

valid subdelims according to RFC 3986 Appendix 1: "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "="

Definition at line 63 of file URI.php.

◆ UNRESERVED

const ILIAS\Data\URI::UNRESERVED = self::ALPHA_DIGIT . '|[\\-\\._~]'

Definition at line 69 of file URI.php.

◆ UNRESERVED_NO_DOT

const ILIAS\Data\URI::UNRESERVED_NO_DOT = self::ALPHA_DIGIT . '|[\\-_~]'

Definition at line 70 of file URI.php.


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