1 | <?php |
||
23 | class Fragment extends AbstractComponent implements FragmentInterface |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * Preserve the delimiter |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected $preserveDelimiter = false; |
||
32 | |||
33 | /** |
||
34 | * new instance |
||
35 | * |
||
36 | * @param string|null $data the component value |
||
37 | */ |
||
38 | 784 | public function __construct($data = null) |
|
39 | { |
||
40 | 784 | $this->data = $this->validate($data); |
|
41 | 772 | $this->preserveDelimiter = null !== $data; |
|
42 | 772 | } |
|
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | 12 | public static function __set_state(array $properties) |
|
48 | { |
||
49 | 12 | $component = new static($properties['data']); |
|
50 | 12 | $component->preserveDelimiter = $properties['preserveDelimiter']; |
|
51 | |||
52 | 12 | return $component; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns the component literal value |
||
57 | * |
||
58 | * @return string|null |
||
59 | */ |
||
60 | 760 | public function getContent() |
|
61 | { |
||
62 | 760 | if (null === $this->data && false === $this->preserveDelimiter) { |
|
63 | 456 | return null; |
|
64 | } |
||
65 | |||
66 | 391 | return $this->encodeQueryFragment($this->data); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Return the decoded string representation of the component |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 30 | public function getValue() |
|
75 | { |
||
76 | 30 | return (string) $this->data; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Returns the instance string representation |
||
81 | * with its optional URI delimiters |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | 725 | public function getUriComponent() |
|
86 | { |
||
87 | 725 | $component = $this->__toString(); |
|
88 | 725 | if ($this->preserveDelimiter) { |
|
89 | 383 | return FragmentInterface::DELIMITER.$component; |
|
90 | } |
||
91 | |||
92 | 429 | return $component; |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * Returns an instance with the specified string |
||
97 | * |
||
98 | * This method MUST retain the state of the current instance, and return |
||
99 | * an instance that contains the modified data |
||
100 | * |
||
101 | * @param string $value |
||
102 | * |
||
103 | * @return static |
||
104 | */ |
||
105 | 9 | public function modify($value) |
|
117 | } |
||
118 |