1 | <?php |
||
9 | abstract class AbstractCondition implements ConditionInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $code; |
||
15 | |||
16 | /** |
||
17 | * @var TargetDefinitionInterface |
||
18 | */ |
||
19 | protected $targetDefinition; |
||
20 | |||
21 | 1 | public function attach(TargetDefinitionInterface $target, $code) |
|
22 | { |
||
23 | $this->code = $code; |
||
24 | $this->targetDefinition = $target; |
||
25 | 1 | $this->targetDefinition->setCondition($this->code, $this); |
|
26 | } |
||
27 | |||
28 | 2 | public function match($object) |
|
29 | { |
||
30 | 2 | if (!$this->supports($object)) { |
|
31 | 1 | throw ConditionException::unsupportedArgumentToMatch($this, $object); |
|
32 | } |
||
33 | |||
34 | 1 | return $this->doMatch($object); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * Checks whether the object is valid argument to perform matching |
||
39 | * |
||
40 | * @param mixed $object |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | abstract protected function supports($object); |
||
45 | |||
46 | /** |
||
47 | * Verify that object matches according to condition configuration |
||
48 | * |
||
49 | * @param $object |
||
50 | * |
||
51 | * @return int|null |
||
52 | */ |
||
53 | abstract protected function doMatch($object); |
||
54 | } |
||
55 |