1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Variables_Collection_Regular} class. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Variables |
7
|
|
|
* @see Mailcode_Variables_Collection_Regular |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Handler for all variable-related tasks. |
16
|
|
|
* |
17
|
|
|
* @package Mailcode |
18
|
|
|
* @subpackage Variables |
19
|
|
|
* @author Sebastian Mordziol <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Mailcode_Variables_Collection_Regular extends Mailcode_Variables_Collection |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Mailcode_Variables_Collection_Invalid |
25
|
|
|
*/ |
26
|
|
|
protected $invalid; |
27
|
|
|
|
28
|
|
|
protected function init() : void |
29
|
|
|
{ |
30
|
|
|
$this->invalid = new Mailcode_Variables_Collection_Invalid(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function add(Mailcode_Variables_Variable $variable) : Mailcode_Variables_Collection |
34
|
|
|
{ |
35
|
|
|
if(!$variable->isValid()) |
36
|
|
|
{ |
37
|
|
|
return $this->addInvalid($variable); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return parent::add($variable); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function addInvalid(Mailcode_Variables_Variable $variable) : Mailcode_Variables_Collection_Regular |
44
|
|
|
{ |
45
|
|
|
$this->invalid->add($variable); |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Whether any of the variables in the collection are invalid. |
52
|
|
|
* |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function hasInvalid() : bool |
56
|
|
|
{ |
57
|
|
|
return isset($this->invalid) && $this->invalid->hasVariables(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Retrieves the collection of invalid variables, if any. |
62
|
|
|
* Behaves like a variables collection. |
63
|
|
|
* |
64
|
|
|
* @return Mailcode_Variables_Collection_Invalid |
65
|
|
|
*/ |
66
|
|
|
public function getInvalid() : Mailcode_Variables_Collection_Invalid |
67
|
|
|
{ |
68
|
|
|
return $this->invalid; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return Mailcode_Variables_Collection_Regular |
73
|
|
|
*/ |
74
|
|
|
public function mergeWith(Mailcode_Variables_Collection $collection) : Mailcode_Variables_Collection |
75
|
|
|
{ |
76
|
|
|
parent::mergeWith($collection); |
77
|
|
|
|
78
|
|
|
// also inherit any invalid variables |
79
|
|
|
if($collection instanceof Mailcode_Variables_Collection_Regular) |
80
|
|
|
{ |
81
|
|
|
$invalid = $collection->getInvalid(); |
82
|
|
|
|
83
|
|
|
$this->invalid->mergeWith($invalid); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|