1 | <?php |
||
25 | trait ImmutableComponentTrait |
||
26 | { |
||
27 | use ValidatorTrait; |
||
28 | |||
29 | /** |
||
30 | * Characters to conform to RFC3986 - http://tools.ietf.org/html/rfc3986#section-2 |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected static $characters_set = [ |
||
35 | '!', '$', '&', "'", '(', ')', '*', '+', ',', ';', '=', ':', |
||
36 | ]; |
||
37 | |||
38 | protected static $characters_set_compiled; |
||
39 | |||
40 | /** |
||
41 | * Encoded characters to conform to RFC3986 - http://tools.ietf.org/html/rfc3986#section-2 |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected static $characters_set_encoded = [ |
||
46 | '%21', '%24', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C', '%3B', '%3D', '%3A', |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * Invalid Characters list |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected static $invalidCharactersRegex; |
||
55 | |||
56 | /** |
||
57 | * Check the string against RFC3986 rules |
||
58 | * |
||
59 | * @param string $str |
||
60 | * |
||
61 | * @throws InvalidArgumentException If the string is invalid |
||
62 | */ |
||
63 | 864 | protected function assertValidComponent($str) |
|
64 | { |
||
65 | 864 | if (!empty(static::$invalidCharactersRegex) && preg_match(static::$invalidCharactersRegex, $str)) { |
|
66 | 26 | throw new InvalidArgumentException('The component contains invalid characters'); |
|
67 | } |
||
68 | 838 | } |
|
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | 24 | public function sameValueAs(UriPart $component) |
|
74 | { |
||
75 | 24 | return $component->getUriComponent() === $this->getUriComponent(); |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | abstract public function getUriComponent(); |
||
82 | |||
83 | /** |
||
84 | * @inheritdoc |
||
85 | */ |
||
86 | abstract public function __toString(); |
||
87 | |||
88 | 852 | protected static function getReservedRegex() |
|
89 | { |
||
96 | |||
97 | /** |
||
98 | * Encoding string according to RFC3986 |
||
99 | * |
||
100 | * @param string $value |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 816 | protected static function encode($value) |
|
118 | |||
119 | /** |
||
120 | * @inheritdoc |
||
121 | */ |
||
122 | 356 | public function modify($value) |
|
130 | } |
||
131 |