1 | <?php |
||
13 | class Mustache implements Processor |
||
14 | { |
||
15 | use Processor\Implementation, |
||
16 | Helper\GetByReference |
||
17 | { |
||
18 | Helper\GetByReference::withSourceAndTarget insteadof Processor\Implementation; |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Apply processing to a single node |
||
23 | * |
||
24 | * @param Node $node |
||
25 | */ |
||
26 | 4 | public function applyToNode(Node $node) |
|
37 | |||
38 | /** |
||
39 | * Parse a template by mustache if possible and return the result |
||
40 | * |
||
41 | * @param mixed $template |
||
42 | * |
||
43 | * @return mixed $result |
||
44 | */ |
||
45 | 4 | protected function getParsedResult($template) |
|
57 | |||
58 | /** |
||
59 | * Parse an object with mustache |
||
60 | * |
||
61 | * @param object $template |
||
62 | * |
||
63 | * @return object $result |
||
64 | */ |
||
65 | 2 | protected function parseObject($template) |
|
66 | { |
||
67 | 2 | $result = new \stdClass(); |
|
68 | |||
69 | 2 | foreach ($template as $key => $value) { |
|
70 | 2 | $parsedKey = $this->parse($key); |
|
71 | 2 | $parsedValue = $this->getParsedResult($value); |
|
72 | 2 | $result->$parsedKey = $parsedValue; |
|
73 | } |
||
74 | |||
75 | 2 | return $result; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Parse as mustache template |
||
80 | * |
||
81 | * @param string $template |
||
82 | */ |
||
83 | 4 | protected function parse($template) |
|
90 | } |
||
91 |