| @@ 12-73 (lines=62) @@ | ||
| 9 | /** |
|
| 10 | * Decode processor |
|
| 11 | */ |
|
| 12 | class Decode implements Processor |
|
| 13 | { |
|
| 14 | use Processor\Implementation; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Apply processing to a single node |
|
| 18 | * |
|
| 19 | * @param Node $node |
|
| 20 | */ |
|
| 21 | public function applyToNode(Node $node) |
|
| 22 | { |
|
| 23 | $instruction = $node->getInstruction($this); |
|
| 24 | ||
| 25 | if (is_array($instruction) || is_object($instruction)) { |
|
| 26 | $instruction = (object)$instruction; |
|
| 27 | } |
|
| 28 | ||
| 29 | if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->algo)) { |
|
| 30 | return; |
|
| 31 | } |
|
| 32 | ||
| 33 | if (!method_exists($this, $instruction->algo)) { |
|
| 34 | return; |
|
| 35 | } |
|
| 36 | ||
| 37 | $result = call_user_func_array([$this, $instruction->algo], [$instruction->input]); |
|
| 38 | ||
| 39 | $node->setResult($result); |
|
| 40 | } |
|
| 41 | ||
| 42 | ||
| 43 | /** |
|
| 44 | * Base64 decode |
|
| 45 | * |
|
| 46 | * @param string $input |
|
| 47 | */ |
|
| 48 | public function base64($input) |
|
| 49 | { |
|
| 50 | return base64_decode($input); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Base58 decode |
|
| 55 | * |
|
| 56 | * @param string $input |
|
| 57 | */ |
|
| 58 | public function base58($input) |
|
| 59 | { |
|
| 60 | $base58 = new Base58(); |
|
| 61 | return $base58->decode($input); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Url decode |
|
| 66 | * |
|
| 67 | * @param string $input |
|
| 68 | */ |
|
| 69 | public function url($input) |
|
| 70 | { |
|
| 71 | return urldecode($input); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | ||
| @@ 12-73 (lines=62) @@ | ||
| 9 | /** |
|
| 10 | * Encode processor |
|
| 11 | */ |
|
| 12 | class Encode implements Processor |
|
| 13 | { |
|
| 14 | use Processor\Implementation; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Apply processing to a single node |
|
| 18 | * |
|
| 19 | * @param Node $node |
|
| 20 | */ |
|
| 21 | public function applyToNode(Node $node) |
|
| 22 | { |
|
| 23 | $instruction = $node->getInstruction($this); |
|
| 24 | ||
| 25 | if (is_array($instruction) || is_object($instruction)) { |
|
| 26 | $instruction = (object)$instruction; |
|
| 27 | } |
|
| 28 | ||
| 29 | if (!isset($instruction) || !isset($instruction->input) || !isset($instruction->algo)) { |
|
| 30 | return; |
|
| 31 | } |
|
| 32 | ||
| 33 | if (!method_exists($this, $instruction->algo)) { |
|
| 34 | return; |
|
| 35 | } |
|
| 36 | ||
| 37 | $result = call_user_func_array([$this, $instruction->algo], [$instruction->input]); |
|
| 38 | ||
| 39 | $node->setResult($result); |
|
| 40 | } |
|
| 41 | ||
| 42 | ||
| 43 | /** |
|
| 44 | * Base64 encode |
|
| 45 | * |
|
| 46 | * @param string $input |
|
| 47 | */ |
|
| 48 | public function base64($input) |
|
| 49 | { |
|
| 50 | return base64_encode($input); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * Base58 encode |
|
| 55 | * |
|
| 56 | * @param string $input |
|
| 57 | */ |
|
| 58 | public function base58($input) |
|
| 59 | { |
|
| 60 | $base58 = new Base58(); |
|
| 61 | return $base58->encode($input); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Url encode |
|
| 66 | * |
|
| 67 | * @param string $input |
|
| 68 | */ |
|
| 69 | public function url($input) |
|
| 70 | { |
|
| 71 | return urlencode($input); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | ||