1 | <?php namespace Cornford\Bencoded; |
||
6 | class Encoder implements EncodableInterface |
||
7 | { |
||
8 | const TYPE_ARRAY = 0; |
||
9 | const TYPE_OBJECT = 1; |
||
10 | const TYPE_INTEGER = 2; |
||
11 | const TYPE_DOUBLE = 3; |
||
12 | const TYPE_STRING = 4; |
||
13 | |||
14 | const DELIMITER_END = 'e'; |
||
15 | const DELIMITER_DICTIONARY = 'd'; |
||
16 | const DELIMITER_INTEGER = 'i'; |
||
17 | const DELIMITER_LIST = 'l'; |
||
18 | |||
19 | const HEX_NULL = "\x00"; |
||
20 | |||
21 | const SEPARATOR = ':'; |
||
22 | |||
23 | /** |
||
24 | * Content. |
||
25 | * |
||
26 | * @var mixed |
||
27 | */ |
||
28 | private $content; |
||
29 | |||
30 | /** |
||
31 | * Encode content. |
||
32 | * |
||
33 | * @param mixed $content |
||
34 | * |
||
35 | * @throws InvalidEncodeInputException |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | public function encode($content) |
||
45 | |||
46 | /** |
||
47 | * Process from the current position. |
||
48 | * |
||
49 | * @throws InvalidEncodeInputException |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | private function process() |
||
69 | |||
70 | /** |
||
71 | * Get type of the value at the current pointer. |
||
72 | * |
||
73 | * @throws InvalidEncodeInputException |
||
74 | * |
||
75 | * @return integer |
||
76 | */ |
||
77 | private function getCurrentType() |
||
96 | |||
97 | /** |
||
98 | * Encode string. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | private function encodeString() |
||
106 | |||
107 | /** |
||
108 | * Encode integer. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | private function encodeInteger() |
||
116 | |||
117 | /** |
||
118 | * Encode array. |
||
119 | * |
||
120 | * @throws InvalidEncodeInputException |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | private function encodeArray() |
||
136 | |||
137 | /** |
||
138 | * Encode list. |
||
139 | * |
||
140 | * @throws InvalidEncodeInputException |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | private function encodeList() |
||
154 | |||
155 | /** |
||
156 | * Encode dictionary. |
||
157 | * |
||
158 | * @throws InvalidEncodeInputException |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | private function encodeDictionary() |
||
179 | |||
180 | /** |
||
181 | * Is list? |
||
182 | * |
||
183 | * @param array $array |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | private function isList(array $array) |
||
197 | |||
198 | /** |
||
199 | * Is dictionary? |
||
200 | * |
||
201 | * @param array $array |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | private function isDictionary(array $array) |
||
215 | |||
216 | /** |
||
217 | * Encode object. |
||
218 | * |
||
219 | * @throws InvalidEncodeInputException |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | private function encodeObject() |
||
233 | } |
||
234 |