| 1 | <?php |
||
| 17 | class Dictionary extends AbstractCollectionArray implements MapInterface, \ArrayAccess |
||
| 18 | { |
||
| 19 | use StrictKeyedIterableTrait, |
||
| 20 | GuardTrait; |
||
| 21 | |||
| 22 | public function at($k) |
||
| 26 | |||
| 27 | 21 | public function set($key, $value) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | 8 | public function get($index) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | 11 | public function add($key, $value) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | 4 | public function addAll($items) |
|
| 63 | { |
||
| 64 | 4 | if (!is_array($items) && !$items instanceof Traversable) { |
|
| 65 | 1 | throw new \InvalidArgumentException('The items must be an array or Traversable'); |
|
| 66 | } |
||
| 67 | |||
| 68 | 3 | foreach ($items as $key => $value) { |
|
| 69 | 3 | if (is_array($value)) { |
|
| 70 | 1 | $value = Dictionary::fromArray($value); |
|
| 71 | } |
||
| 72 | 3 | $this->add($key, $value); |
|
| 73 | } |
||
| 74 | 3 | } |
|
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | 16 | public function containsKey($key) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | public function contains($element) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | 2 | public function remove($element) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * {@inheritdoc} |
||
| 105 | */ |
||
| 106 | 1 | public function removeKey($key) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | */ |
||
| 114 | 5 | public function offsetExists($offset) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | 5 | public function offsetGet($offset) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc} |
||
| 129 | */ |
||
| 130 | 10 | public function offsetSet($offset, $value) |
|
| 131 | { |
||
| 132 | 10 | if (is_null($offset)) { |
|
| 133 | $this->add($offset, $value); |
||
| 134 | } else { |
||
| 135 | 10 | $this->set($offset, $value); |
|
| 136 | } |
||
| 137 | 10 | } |
|
| 138 | |||
| 139 | /** |
||
| 140 | * {@inheritdoc} |
||
| 141 | */ |
||
| 142 | 1 | public function offsetUnset($offset) |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Gets the collection's iterator |
||
| 149 | * @return MapIterator |
||
| 150 | */ |
||
| 151 | 9 | public function getIterator() |
|
| 155 | |||
| 156 | } |
||
|
1 ignored issue
–
show
|
|||
| 157 |
Below you find some examples: