1 | <?php |
||
14 | abstract class AbstractRule implements RuleInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var string The label for the rule. |
||
18 | */ |
||
19 | protected $name; |
||
20 | |||
21 | /** |
||
22 | * @var callable The function which is performed after scanning. |
||
23 | */ |
||
24 | protected $action; |
||
25 | |||
26 | /** |
||
27 | * Returns the value of the label. |
||
28 | * |
||
29 | * @return string |
||
30 | */ |
||
31 | 1 | public function getName() |
|
32 | { |
||
33 | 1 | return $this->name; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Launches action. |
||
38 | * |
||
39 | * @param Result $result |
||
40 | * @return void |
||
41 | */ |
||
42 | 8 | public function action(Result $result = null) |
|
43 | { |
||
44 | 8 | if ($this->action !== null) { |
|
45 | 1 | $action = $this->action; |
|
46 | 1 | $action($result); |
|
47 | } |
||
48 | 8 | } |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | abstract public function scan(Context $context); |
||
54 | |||
55 | /** |
||
56 | * This method converts the input value to an object that implements an interface Rule. |
||
57 | * |
||
58 | * @param $rule |
||
59 | * @return RuleInterface |
||
60 | */ |
||
61 | 12 | public function toRule($rule) |
|
71 | } |
||
72 |