|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Richard Klees <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This software is licensed under The MIT License. You should have received |
|
8
|
|
|
* a copy of the licence along with the code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\Rules; |
|
12
|
|
|
|
|
13
|
|
|
use Lechimp\Dicto\Definition as Def; |
|
14
|
|
|
use Lechimp\Dicto\Variables as Vars; |
|
15
|
|
|
use Lechimp\Dicto\Indexer\ListenerRegistry; |
|
16
|
|
|
use Lechimp\Dicto\Analysis\Query; |
|
17
|
|
|
use Lechimp\Dicto\Variables\Variable; |
|
18
|
|
|
use Doctrine\DBAL\Driver\Statement; |
|
19
|
|
|
use Doctrine\DBAL\Query\Expression\ExpressionBuilder; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* This is what every rule needs to define. |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class Schema { |
|
25
|
|
|
/** |
|
26
|
|
|
* Get the name of the relation. |
|
27
|
|
|
* |
|
28
|
|
|
* This must return a string without whitespaces. |
|
29
|
|
|
* |
|
30
|
|
|
* @return string |
|
31
|
|
|
*/ |
|
32
|
|
|
abstract public function name(); |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get the name where _ is replace by space. |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
3 |
|
public function printable_name() { |
|
40
|
3 |
|
return str_replace("_", " ", $this->name()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get the Fluid interface that should be returned on using the |
|
45
|
|
|
* schema. |
|
46
|
|
|
* |
|
47
|
|
|
* @param Def\RuleDefinitionRT $rt |
|
48
|
|
|
* @param string $name |
|
49
|
|
|
* @param string $mode |
|
50
|
|
|
* @param array $arguments |
|
51
|
|
|
* @return Def\Fluid\Base|null |
|
52
|
|
|
*/ |
|
53
|
|
|
abstract public function fluid_interface(Def\RuleDefinitionRT $rt, $name, $mode, array $arguments); |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Check the arguments given in the fluid interface on using the schema. |
|
57
|
|
|
* |
|
58
|
|
|
* @param array $arguments |
|
59
|
|
|
* @throws \InvalidArgumentException if $arguments are not ok |
|
60
|
|
|
* @return null |
|
61
|
|
|
*/ |
|
62
|
|
|
abstract public function check_arguments(array $arguments); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get a pretty printed version of the rules. |
|
66
|
|
|
* |
|
67
|
|
|
* @param Rule $rule |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
abstract public function pprint(Rule $rule); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Compile a given rule into an sql statement using a query interface. |
|
74
|
|
|
* |
|
75
|
|
|
* @param Query $query |
|
76
|
|
|
* @param Rule $rule |
|
77
|
|
|
* @return Statement |
|
78
|
|
|
*/ |
|
79
|
|
|
abstract public function compile(Query $query, Rule $rule); |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Register listeners to the indexer that are required to detect information |
|
83
|
|
|
* for the rule. |
|
84
|
|
|
* |
|
85
|
|
|
* @param ListenerRegistry $registry |
|
86
|
|
|
* @return null |
|
87
|
|
|
*/ |
|
88
|
|
|
abstract public function register_listeners(ListenerRegistry $registry); |
|
89
|
|
|
} |
|
90
|
|
|
|