1 | <?php |
||
9 | class FunctionSet { |
||
10 | private $elementData; |
||
11 | private $functions = []; |
||
12 | private $element; |
||
13 | |||
14 | public function __construct(Hook\ElementData $elementData) { |
||
17 | |||
18 | public function __call($name, $args) { |
||
19 | try { |
||
20 | if (isset($this->functions[$name])) { |
||
21 | return $this->functions[$name]->run($this->getArgs0($name, $args), $this->element); |
||
22 | } |
||
23 | } |
||
24 | catch (\Exception $e) { |
||
25 | throw new RunException(Exception::TSS_FUNCTION, $name, $e); |
||
26 | } |
||
27 | return true; |
||
28 | } |
||
29 | |||
30 | private function getArgs0($name, $args) { |
||
31 | if (isset($this->functions[$name]) && !($this->functions[$name] instanceof TSSFunction\Data)) { |
||
32 | $tokens = $args[0]; |
||
33 | $parser = new \Transphporm\Parser\Value($this); |
||
34 | return $parser->parseTokens($tokens, $this->elementData->getData($this->element)); |
||
35 | } |
||
36 | else if ($args[0] instanceof Parser\Tokens) { |
||
37 | return iterator_to_array($args[0]); |
||
38 | } |
||
39 | |||
40 | return $args[0]; |
||
41 | } |
||
42 | |||
43 | public function addFunction($name, \Transphporm\TSSFunction $function) { |
||
46 | |||
47 | public function hasFunction($name) { |
||
50 | |||
51 | public function setElement(\DomElement $element) { |
||
54 | |||
55 | } |
||
56 |