1 | <?php |
||
13 | abstract class AbstractCompiler implements StatementCompilerInterface |
||
14 | { |
||
15 | /** |
||
16 | * @abstract |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $name = 'unknown'; |
||
20 | |||
21 | 6 | protected function assertExpression($expression) |
|
22 | { |
||
23 | 6 | if (!$expression instanceof $this->name) { |
|
24 | throw new RuntimeException('Passed $expression must be instance of ' . $this->name); |
||
25 | } |
||
26 | 6 | } |
|
27 | |||
28 | /** |
||
29 | * @param $stmt |
||
30 | * @param Context $context |
||
31 | * @return CompiledExpression |
||
32 | */ |
||
33 | 6 | public function pass($stmt, Context $context) |
|
34 | { |
||
35 | 6 | $this->assertExpression($stmt); |
|
36 | 6 | return $this->compile($stmt, $context); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getName() |
||
46 | |||
47 | /** |
||
48 | * @param $expr |
||
49 | * @param Context $context |
||
50 | * @return mixed |
||
51 | */ |
||
52 | abstract protected function compile($expr, Context $context); |
||
53 | } |
||
54 |