1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace prgTW\BaseCRM\Resource; |
4
|
|
|
|
5
|
|
|
class CustomFieldsCollection implements \ArrayAccess, \Iterator, \Countable |
6
|
|
|
{ |
7
|
|
|
/** @var array|CustomField[] */ |
8
|
|
|
protected $customFields; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param array|CustomField[] $customFields |
12
|
|
|
*/ |
13
|
|
|
public function __construct(array $customFields) |
14
|
|
|
{ |
15
|
|
|
$this->customFields = $customFields; |
16
|
|
|
$this->rewind(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function toArray() |
23
|
|
|
{ |
24
|
|
|
$array = []; |
25
|
|
|
foreach ($this as $customField) |
26
|
|
|
{ |
27
|
|
|
$array[$customField->getName()] = $customField->getValue(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return $array; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return array|CustomField[] |
35
|
|
|
*/ |
36
|
|
|
public function getItems() |
37
|
|
|
{ |
38
|
|
|
return $this->customFields; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** {@inheritdoc} */ |
42
|
|
|
public function offsetExists($offset) |
43
|
|
|
{ |
44
|
|
|
return array_key_exists($offset, $this->customFields); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** {@inheritdoc} */ |
48
|
|
|
public function offsetGet($offset) |
49
|
|
|
{ |
50
|
|
|
return $this->customFields[$offset]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** {@inheritdoc} */ |
54
|
|
|
public function offsetSet($offset, $value) |
55
|
|
|
{ |
56
|
|
|
$this->customFields[$offset] = $value; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** {@inheritdoc} */ |
60
|
|
|
public function offsetUnset($offset) |
61
|
|
|
{ |
62
|
|
|
unset($this->customFields[$offset]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return CustomField|null |
67
|
|
|
*/ |
68
|
|
|
public function current() |
69
|
|
|
{ |
70
|
|
|
return current($this->customFields); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return CustomField|null |
75
|
|
|
*/ |
76
|
|
|
public function next() |
77
|
|
|
{ |
78
|
|
|
return next($this->customFields); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** {@inheritdoc} */ |
82
|
|
|
public function key() |
83
|
|
|
{ |
84
|
|
|
return key($this->customFields); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** {@inheritdoc} */ |
88
|
|
|
public function valid() |
89
|
|
|
{ |
90
|
|
|
return null !== $this->key(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** {@inheritdoc} */ |
94
|
|
|
public function rewind() |
95
|
|
|
{ |
96
|
|
|
reset($this->customFields); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** {@inheritdoc} */ |
100
|
|
|
public function count() |
101
|
|
|
{ |
102
|
|
|
return count($this->customFields); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|