1 <?php namespace Modulework\Modules\Http\Utilities;
2 /*
3 * (c) Christian Gärtner <christiangaertner.film@googlemail.com>
4 * This file is part of the Modulework Framework
5 * License: View distributed LICENSE file
6 */
7
8
9 /**
10 * {@inheritdoc}
11 */
12 class ArrayCase implements ArrayCaseInterface, \Countable, \IteratorAggregate
13 {
14 /**
15 * The array which gets "wrap" by this class
16 * @var array
17 */
18 protected $array;
19
20 /**
21 * {@inheritdoc}
22 */
23 public function __construct(array $array = array())
24 {
25 $this->array = $array;
26 }
27
28 /**
29 * {@inheritdoc}
30 */
31 public function all()
32 {
33 return $this->array;
34 }
35
36 /**
37 * {@inheritdoc}
38 */
39 public function get($key, $default = null)
40 {
41 return array_key_exists($key, $this->array) ? $this->array[$key] : $default;
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function set($key, $value, $override = false)
48 {
49 if ($this->has($key) && !$override) {
50 return false;
51 }
52
53 $this->array[$key] = $value;
54 return true;
55
56 }
57
58 /**
59 * {@inheritdoc}
60 */
61 public function has($key)
62 {
63 return array_key_exists($key, $this->array);
64 }
65
66 /**
67 * {@inheritdoc}
68 */
69 public function remove($key)
70 {
71 unset($this->array[$key]);
72 }
73
74 /**
75 * {@inheritdoc}
76 */
77 public function merge(array $array = array())
78 {
79 $this->array = array_merge($this->array, $array);
80 }
81
82 /**
83 * {@inheritdoc}
84 */
85 public function mock(array $array = array())
86 {
87 $this->array = $array;
88 }
89
90 /**
91 * {@inheritdoc}
92 */
93 public function keys()
94 {
95 return array_keys($this->array);
96 }
97
98 /**
99 * {@inheritdoc}
100 */
101 public function push($value)
102 {
103 $this->array[] = $value;
104 }
105
106 /**
107 * {@inheritdoc}
108 */
109 public function getIterator()
110 {
111 return new \ArrayIterator($this->array);
112 }
113
114 /**
115 * {@inheritdoc}
116 */
117 public function count()
118 {
119 return count($this->array);
120 }
121
122 }