-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathExpressionCollection.php
More file actions
91 lines (75 loc) · 1.85 KB
/
Copy pathExpressionCollection.php
File metadata and controls
91 lines (75 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace ProcessMaker\Query;
use ArrayAccess;
use Exception;
use Iterator;
/**
* Represents a list of expressions
*/
class ExpressionCollection extends BaseExpression implements ArrayAccess, Iterator
{
protected $expressions;
// Iterator position
private $_position;
public function __construct($logical = 'AND')
{
parent::__construct($logical);
$this->expressions = [];
$this->_position = 0;
}
public function offsetSet($offset, $value)
{
if (!is_a($value, BaseExpression::class)) {
throw new Exception('Cannot set a non expression to an ExpressionCollection');
}
if (is_null($offset)) {
// Append
$this->expressions[] = $value;
} else {
$this->expressions[$offset] = $value;
}
}
public function offsetExists($offset)
{
return isset($this->expressions[$offset]);
}
public function offsetUnset($offset)
{
unset($this->expressions[$offset]);
}
public function offsetGet($offset)
{
return isset($this->expressions[$offset]) ? $this->expressions[$offset] : null;
}
public function toArray()
{
$expressions = [];
foreach ($this->expressions as $expression) {
$expressions[] = $expression->toArray();
}
return [
'logical' => $this->logical,
'expressions' => $expressions,
];
}
public function rewind()
{
$this->_position = 0;
}
public function current()
{
return $this->expressions[$this->_position];
}
public function key()
{
return $this->_position;
}
public function next()
{
$this->_position++;
}
public function valid()
{
return isset($this->expressions[$this->_position]);
}
}