1 | <?php namespace Arcanedev\Stripe\Utilities; |
||
14 | class UtilSet implements UtilSetContract, IteratorAggregate, Countable |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Properties |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | /** @var array */ |
||
21 | private $items; |
||
22 | |||
23 | /* ------------------------------------------------------------------------------------------------ |
||
24 | | Constructor |
||
25 | | ------------------------------------------------------------------------------------------------ |
||
26 | */ |
||
27 | 508 | public function __construct($attributes = []) |
|
28 | { |
||
29 | 508 | $this->items = []; |
|
30 | |||
31 | 508 | foreach ($attributes as $attribute) { |
|
32 | 504 | $this->add($attribute); |
|
33 | } |
||
34 | 508 | } |
|
35 | |||
36 | /* ------------------------------------------------------------------------------------------------ |
||
37 | | Main Functions |
||
38 | | ------------------------------------------------------------------------------------------------ |
||
39 | */ |
||
40 | /** |
||
41 | * Check if attribute is included. |
||
42 | * |
||
43 | * @param string $attribute |
||
44 | * |
||
45 | * @return bool |
||
46 | */ |
||
47 | 456 | public function includes($attribute) |
|
51 | |||
52 | /** |
||
53 | * Add attribute |
||
54 | * |
||
55 | * @param $attribute |
||
56 | */ |
||
57 | 506 | public function add($attribute) |
|
61 | |||
62 | /** |
||
63 | * @param $attribute |
||
64 | */ |
||
65 | 404 | public function discard($attribute) |
|
69 | |||
70 | /** |
||
71 | * Get all attributes key |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | 94 | public function keys() |
|
79 | |||
80 | /** |
||
81 | * Diff Keys |
||
82 | * |
||
83 | * @param array $keys |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | 16 | public function diffKeys(array $keys = []) |
|
91 | |||
92 | /** |
||
93 | * Get all Attributes |
||
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | 102 | public function toArray() |
|
101 | |||
102 | /** |
||
103 | * @return ArrayIterator |
||
104 | */ |
||
105 | 12 | public function getIterator() |
|
109 | |||
110 | /** |
||
111 | * Count items |
||
112 | * |
||
113 | * @return int The custom count as an integer. |
||
114 | */ |
||
115 | 104 | public function count() |
|
119 | |||
120 | /* ------------------------------------------------------------------------------------------------ |
||
121 | | Check Functions |
||
122 | | ------------------------------------------------------------------------------------------------ |
||
123 | */ |
||
124 | /** |
||
125 | * Check if the items are empty. |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | 6 | public function isEmpty() |
|
133 | } |
||
134 |