| @@ 11-61 (lines=51) @@ | ||
| 8 | /** |
|
| 9 | * Serialize processor |
|
| 10 | */ |
|
| 11 | class Serialize implements Processor |
|
| 12 | { |
|
| 13 | use Processor\Implementation; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * Apply processing to a single node |
|
| 17 | * |
|
| 18 | * @param Node $node |
|
| 19 | */ |
|
| 20 | public function applyToNode(Node $node) |
|
| 21 | { |
|
| 22 | $instruction = $node->getInstruction($this); |
|
| 23 | ||
| 24 | if (is_array($instruction) || is_object($instruction)) { |
|
| 25 | $instruction = (object)$instruction; |
|
| 26 | } |
|
| 27 | ||
| 28 | if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->format)) { |
|
| 29 | return; |
|
| 30 | } |
|
| 31 | ||
| 32 | if (!method_exists($this, $instruction->format)) { |
|
| 33 | return; |
|
| 34 | } |
|
| 35 | ||
| 36 | $result = call_user_func_array([$this, $instruction->format], [$instruction->input]); |
|
| 37 | ||
| 38 | $node->setResult($result); |
|
| 39 | } |
|
| 40 | ||
| 41 | ||
| 42 | /** |
|
| 43 | * Json serialize |
|
| 44 | * |
|
| 45 | * @param mixed $input |
|
| 46 | */ |
|
| 47 | public function json($input) |
|
| 48 | { |
|
| 49 | return json_encode($input); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Url serialize |
|
| 54 | * |
|
| 55 | * @param stdClass $input |
|
| 56 | */ |
|
| 57 | public function url($input) |
|
| 58 | { |
|
| 59 | return http_build_query($input); |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 11-62 (lines=52) @@ | ||
| 8 | /** |
|
| 9 | * Unserialize processor |
|
| 10 | */ |
|
| 11 | class Unserialize implements Processor |
|
| 12 | { |
|
| 13 | use Processor\Implementation; |
|
| 14 | ||
| 15 | /** |
|
| 16 | * Apply processing to a single node |
|
| 17 | * |
|
| 18 | * @param Node $node |
|
| 19 | */ |
|
| 20 | public function applyToNode(Node $node) |
|
| 21 | { |
|
| 22 | $instruction = $node->getInstruction($this); |
|
| 23 | ||
| 24 | if (is_array($instruction) || is_object($instruction)) { |
|
| 25 | $instruction = (object)$instruction; |
|
| 26 | } |
|
| 27 | ||
| 28 | if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->format)) { |
|
| 29 | return; |
|
| 30 | } |
|
| 31 | ||
| 32 | if (!method_exists($this, $instruction->format)) { |
|
| 33 | return; |
|
| 34 | } |
|
| 35 | ||
| 36 | $result = call_user_func_array([$this, $instruction->format], [$instruction->input]); |
|
| 37 | ||
| 38 | $node->setResult($result); |
|
| 39 | } |
|
| 40 | ||
| 41 | ||
| 42 | /** |
|
| 43 | * Json unserialize |
|
| 44 | * |
|
| 45 | * @param string $input |
|
| 46 | */ |
|
| 47 | public function json($input) |
|
| 48 | { |
|
| 49 | return json_decode($input); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * Url unserialize |
|
| 54 | * |
|
| 55 | * @param string $input |
|
| 56 | */ |
|
| 57 | public function url($input) |
|
| 58 | { |
|
| 59 | parse_str($input, $output); |
|
| 60 | return (object)$output; |
|
| 61 | } |
|
| 62 | } |
|
| 63 | ||