1 | <?php |
||
23 | abstract class AbstractComponent |
||
24 | { |
||
25 | use ImmutableComponentTrait; |
||
26 | |||
27 | /** |
||
28 | * The component data |
||
29 | * |
||
30 | * @var int|string |
||
31 | */ |
||
32 | protected $data; |
||
33 | |||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | 12 | public static function __set_state(array $properties) |
|
41 | |||
42 | /** |
||
43 | * new instance |
||
44 | * |
||
45 | * @param string|null $data the component value |
||
46 | */ |
||
47 | 1070 | public function __construct($data = null) |
|
48 | { |
||
49 | 1070 | if ($data !== null) { |
|
50 | 1028 | $this->init($data); |
|
51 | 613 | } |
|
52 | 965 | } |
|
53 | |||
54 | /** |
||
55 | * Set data. |
||
56 | * |
||
57 | * @param mixed $data The data to set. |
||
58 | */ |
||
59 | 1013 | protected function init($data) |
|
64 | |||
65 | /** |
||
66 | * validate the incoming data |
||
67 | * |
||
68 | * @param string $data |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 520 | protected function validate($data) |
|
79 | |||
80 | /** |
||
81 | * Returns the component literal value. The return type can be |
||
82 | * <ul> |
||
83 | * <li> null: If the component is not defined |
||
84 | * <li> int: If the component is a defined port |
||
85 | * <li> string: Otherwise |
||
86 | * </ul> |
||
87 | * |
||
88 | * @return string|int|null |
||
89 | */ |
||
90 | 729 | public function getComponent() |
|
98 | |||
99 | /** |
||
100 | * Returns the instance string representation; If the |
||
101 | * instance is not defined an empty string is returned |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | 957 | public function __toString() |
|
109 | |||
110 | /** |
||
111 | * Returns the instance string representation |
||
112 | * with its optional URI delimiters |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 135 | public function getUriComponent() |
|
120 | |||
121 | /** |
||
122 | * Returns an instance with the specified string |
||
123 | * |
||
124 | * This method MUST retain the state of the current instance, and return |
||
125 | * an instance that contains the modified data |
||
126 | * |
||
127 | * @param string $value |
||
128 | * |
||
129 | * @return static |
||
130 | */ |
||
131 | 291 | public function modify($value) |
|
139 | } |
||
140 |