1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Superdesk Web Publisher Rule Component. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Component\Rule\Processor; |
16
|
|
|
|
17
|
|
|
use SWP\Component\Rule\Applicator\RuleApplicatorInterface; |
18
|
|
|
use SWP\Component\Rule\Evaluator\RuleEvaluatorInterface; |
19
|
|
|
use SWP\Component\Rule\Model\RuleSubjectInterface; |
20
|
|
|
use SWP\Component\Rule\Repository\RuleRepositoryInterface; |
21
|
|
|
|
22
|
|
|
final class RuleProcessor implements RuleProcessorInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var RuleRepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $ruleRepository; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var RuleEvaluatorInterface |
31
|
|
|
*/ |
32
|
|
|
private $ruleEvaluator; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var RuleApplicatorInterface |
36
|
|
|
*/ |
37
|
|
|
private $ruleApplicator; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* RuleProcessor constructor. |
41
|
|
|
* |
42
|
|
|
* @param RuleRepositoryInterface $ruleRepository |
43
|
|
|
* @param RuleEvaluatorInterface $ruleEvaluator |
44
|
|
|
*/ |
45
|
11 |
|
public function __construct( |
46
|
|
|
RuleRepositoryInterface $ruleRepository, |
47
|
|
|
RuleEvaluatorInterface $ruleEvaluator, |
48
|
|
|
RuleApplicatorInterface $ruleApplicator |
49
|
|
|
) { |
50
|
11 |
|
$this->ruleRepository = $ruleRepository; |
51
|
11 |
|
$this->ruleEvaluator = $ruleEvaluator; |
52
|
11 |
|
$this->ruleApplicator = $ruleApplicator; |
53
|
11 |
|
} |
54
|
|
|
|
55
|
9 |
|
public function process(RuleSubjectInterface $subject) |
56
|
|
|
{ |
57
|
9 |
|
$rules = $this->ruleRepository->findBy([], ['priority' => 'desc']); |
58
|
|
|
|
59
|
9 |
|
foreach ($rules as $rule) { |
60
|
3 |
|
if (!$this->ruleEvaluator->evaluate($rule, $subject)) { |
61
|
1 |
|
continue; |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
$this->ruleApplicator->apply($rule, $subject); |
65
|
|
|
} |
66
|
9 |
|
} |
67
|
|
|
} |
68
|
|
|
|