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 license along with the code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\Rules; |
12
|
|
|
|
13
|
|
|
use Lechimp\Dicto\Analysis\Violation; |
14
|
|
|
use Lechimp\Dicto\Definition\ArgumentParser; |
15
|
|
|
use Lechimp\Dicto\Indexer\ListenerRegistry; |
16
|
|
|
use Lechimp\Dicto\Variables\Variable; |
17
|
|
|
use Lechimp\Dicto\Analysis\Index; |
18
|
|
|
use Lechimp\Dicto\Graph\Query; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This is what every rule needs to define. |
22
|
|
|
*/ |
23
|
|
|
abstract class Schema { |
24
|
|
|
/** |
25
|
|
|
* Get the name of the schema. |
26
|
|
|
* |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
abstract public function name(); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Fetch arguments for the Schema from a stream of tokens during parsing. |
33
|
|
|
* |
34
|
|
|
* @param ArgumentParser $parser |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
|
abstract public function fetch_arguments(ArgumentParser $parser); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Check if the given arguments are valid for the rule schema. |
41
|
|
|
* |
42
|
|
|
* @param array $arguments |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
abstract public function arguments_are_valid(array &$arguments); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get a pretty printed version of the rules. |
49
|
|
|
* |
50
|
|
|
* @param Rule $rule |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
abstract public function pprint(Rule $rule); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Compile a given rule into an sql statement using a query interface. |
57
|
|
|
* |
58
|
|
|
* @param Index $index |
59
|
|
|
* @param Rule $rule |
60
|
|
|
* @return Query |
61
|
|
|
*/ |
62
|
|
|
abstract public function compile(Index $index, Rule $rule); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Register listeners to the indexer that are required to detect information |
66
|
|
|
* for the rule. |
67
|
|
|
* |
68
|
|
|
* @param ListenerRegistry $registry |
69
|
|
|
* @return null |
70
|
|
|
*/ |
71
|
|
|
abstract public function register_listeners(ListenerRegistry $registry); |
72
|
|
|
} |
73
|
|
|
|