1 | <?php |
||
11 | class StringEncoder implements Encoder |
||
12 | { |
||
13 | /** @var array Default values for options in the encoder */ |
||
14 | private static $defaultOptions = [ |
||
15 | 'string.escape' => true, |
||
16 | 'string.binary' => false, |
||
17 | 'string.utf8' => false, |
||
18 | ]; |
||
19 | |||
20 | 165 | public function getDefaultOptions() |
|
24 | |||
25 | 99 | public function supports($value) |
|
29 | |||
30 | 60 | public function encode($value, $depth, array $options, callable $encode) |
|
44 | |||
45 | /** |
||
46 | * Tells if the string is not a valid UTF-8 string. |
||
47 | * @param string $string The string to test |
||
48 | * @param array $options The string encoding options |
||
49 | * @return bool True if the string is not valid UTF-8 and false if it is |
||
50 | */ |
||
51 | 15 | private function isBinaryString($string, $options) |
|
72 | |||
73 | /** |
||
74 | * Encodes the given string into base 64 encoded format. |
||
75 | * @param string $string The string to encode |
||
76 | * @return string A base 64 PHP code representation for the string |
||
77 | */ |
||
78 | 3 | private function encodeBinaryString($string) |
|
82 | |||
83 | /** |
||
84 | * Returns the string wrapped in single quotes and escape appropriately. |
||
85 | * @param string $string String to wrap |
||
86 | * @return string The string wrapped in single quotes |
||
87 | */ |
||
88 | 57 | private function getSingleQuotedString($string) |
|
92 | |||
93 | /** |
||
94 | * Returns the string wrapped in double quotes and all but print characters escaped. |
||
95 | * @param string $string String to wrap and escape |
||
96 | * @param array $options The string encoding options |
||
97 | * @return string The string wrapped in double quotes and escape correctly |
||
98 | */ |
||
99 | 9 | private function getDoubleQuotedString($string, $options) |
|
120 | |||
121 | /** |
||
122 | * Encodes all multibyte UTF-8 characters into PHP7 string encoding. |
||
123 | * @param string $string The string to encoder |
||
124 | * @param array $options The string encoding options |
||
125 | * @return string The string with all the multibyte characters encoded |
||
126 | */ |
||
127 | 3 | private function encodeUtf8($string, $options) |
|
142 | |||
143 | /** |
||
144 | * Returns the unicode code point for the given multibyte UTF-8 character. |
||
145 | * @param string $bytes The multibyte character |
||
146 | * @return int The code point for the multibyte character |
||
147 | */ |
||
148 | 3 | private function getCodePoint($bytes) |
|
166 | } |
||
167 |