| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,44 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+namespace Telnyx\Util; |
|
| 4 |
+ |
|
| 5 |
+use IteratorAggregate; |
|
| 6 |
+use ArrayIterator; |
|
| 7 |
+ |
|
| 8 |
+class Set implements IteratorAggregate |
|
| 9 |
+{
|
|
| 10 |
+ private $_elts; |
|
| 11 |
+ |
|
| 12 |
+ public function __construct($members = []) |
|
| 13 |
+ {
|
|
| 14 |
+ $this->_elts = []; |
|
| 15 |
+ foreach ($members as $item) {
|
|
| 16 |
+ $this->_elts[$item] = true; |
|
| 17 |
+ } |
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+ public function includes($elt) |
|
| 21 |
+ {
|
|
| 22 |
+ return isset($this->_elts[$elt]); |
|
| 23 |
+ } |
|
| 24 |
+ |
|
| 25 |
+ public function add($elt) |
|
| 26 |
+ {
|
|
| 27 |
+ $this->_elts[$elt] = true; |
|
| 28 |
+ } |
|
| 29 |
+ |
|
| 30 |
+ public function discard($elt) |
|
| 31 |
+ {
|
|
| 32 |
+ unset($this->_elts[$elt]); |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+ public function toArray() |
|
| 36 |
+ {
|
|
| 37 |
+ return array_keys($this->_elts); |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ public function getIterator() |
|
| 41 |
+ {
|
|
| 42 |
+ return new ArrayIterator($this->toArray()); |
|
| 43 |
+ } |
|
| 44 |
+} |