1 | <?php |
||
25 | trait ImmutableComponentTrait |
||
26 | { |
||
27 | use ValidatorTrait; |
||
28 | |||
29 | /** |
||
30 | * Reserved characters list |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected static $reservedCharactersRegex = "\!\$&'\(\)\*\+,;\=\:"; |
||
35 | |||
36 | /** |
||
37 | * Invalid characters list |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected static $invalidCharactersRegex; |
||
42 | |||
43 | /** |
||
44 | * Asserts the string against RFC3986 rules |
||
45 | * |
||
46 | * @param string $str |
||
47 | * |
||
48 | * @throws InvalidArgumentException If the string is invalid |
||
49 | */ |
||
50 | 1311 | protected function assertValidComponent($str) |
|
51 | { |
||
52 | 1311 | if (isset(static::$invalidCharactersRegex) && preg_match(static::$invalidCharactersRegex, $str)) { |
|
53 | 39 | throw new InvalidArgumentException('The component contains invalid characters'); |
|
54 | } |
||
55 | 1272 | } |
|
56 | |||
57 | /** |
||
58 | * Returns whether two UriPart objects represent the same value |
||
59 | * The comparison is based on the getUriComponent method |
||
60 | * |
||
61 | * @param UriPart $component |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | 36 | public function sameValueAs(UriPart $component) |
|
66 | { |
||
67 | 36 | return $component->getUriComponent() === $this->getUriComponent(); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Returns the instance string representation |
||
72 | * with its optional URI delimiters |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | abstract public function getUriComponent(); |
||
77 | |||
78 | /** |
||
79 | * Returns the instance string representation; If the |
||
80 | * instance is not defined an empty string is returned |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | abstract public function __toString(); |
||
85 | |||
86 | /** |
||
87 | * Encoding string according to RFC3986 |
||
88 | * |
||
89 | * @param string $str |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 726 | protected static function encode($str) |
|
111 | |||
112 | /** |
||
113 | * Returns an instance with the specified string |
||
114 | * |
||
115 | * This method MUST retain the state of the current instance, and return |
||
116 | * an instance that contains the modified data |
||
117 | * |
||
118 | * @param string $value |
||
119 | * |
||
120 | * @return static |
||
121 | */ |
||
122 | 543 | public function modify($value) |
|
130 | } |
||
131 |