1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* League.Uri (http://uri.thephpleague.com) |
4
|
|
|
* |
5
|
|
|
* @package League.uri |
6
|
|
|
* @author Ignace Nyamagana Butera <[email protected]> |
7
|
|
|
* @copyright 2013-2015 Ignace Nyamagana Butera |
8
|
|
|
* @license https://github.com/thephpleague/uri/blob/master/LICENSE (MIT License) |
9
|
|
|
* @version 4.2.0 |
10
|
|
|
* @link https://github.com/thephpleague/uri/ |
11
|
|
|
*/ |
12
|
|
|
namespace League\Uri\Types; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
use League\Uri\Interfaces\UriPart; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Common methods for Component Value Object |
19
|
|
|
* |
20
|
|
|
* @package League.uri |
21
|
|
|
* @author Ignace Nyamagana Butera <[email protected]> |
22
|
|
|
* @since 4.0.0 |
23
|
|
|
*/ |
24
|
|
|
trait ImmutableComponentTrait |
25
|
|
|
{ |
26
|
|
|
use ValidatorTrait; |
27
|
|
|
use TranscoderTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Invalid characters list |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected static $invalidCharactersRegex; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Asserts the string against RFC3986 rules |
38
|
|
|
* |
39
|
|
|
* @param string $str |
40
|
|
|
* |
41
|
|
|
* @throws InvalidArgumentException If the string is invalid |
42
|
|
|
*/ |
43
|
263 |
|
protected function assertValidComponent($str) |
44
|
|
|
{ |
45
|
263 |
|
if (isset(static::$invalidCharactersRegex) && preg_match(static::$invalidCharactersRegex, $str)) { |
46
|
27 |
|
throw new InvalidArgumentException('The component contains invalid characters'); |
47
|
|
|
} |
48
|
236 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns whether two UriPart objects represent the same value |
52
|
|
|
* The comparison is based on the getUriComponent method |
53
|
|
|
* |
54
|
|
|
* @param UriPart $component |
55
|
|
|
* |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
36 |
|
public function sameValueAs(UriPart $component) |
59
|
|
|
{ |
60
|
36 |
|
return $component->getUriComponent() === $this->getUriComponent(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns the instance string representation |
65
|
|
|
* with its optional URI delimiters |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
abstract public function getUriComponent(); |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the instance string representation; If the |
73
|
|
|
* instance is not defined an empty string is returned |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
abstract public function __toString(); |
78
|
|
|
} |
79
|
|
|
|