1
|
|
|
<?php |
2
|
|
|
namespace Germania\FormValidator; |
3
|
|
|
|
4
|
|
|
use Psr\Container\ContainerInterface; |
5
|
|
|
|
6
|
|
|
class InputContainer implements ContainerInterface, \ArrayAccess |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
public $data; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param array $data Input values (optional) |
16
|
|
|
* @param array $defaults Default values (optional) |
17
|
|
|
*/ |
18
|
55 |
|
public function __construct( array $data = array(), array $defaults = array() ) |
19
|
|
|
{ |
20
|
55 |
|
$this->data = array_merge($defaults, $data); |
21
|
55 |
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @implements ContainerInterface |
26
|
|
|
*/ |
27
|
10 |
|
public function get( $offset ) |
28
|
|
|
{ |
29
|
10 |
|
if ($this->offsetExists( $offset )) { |
30
|
5 |
|
return $this->data[ $offset ]; |
31
|
|
|
} |
32
|
5 |
|
throw new NotFoundException; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @implements ContainerInterface |
37
|
|
|
*/ |
38
|
15 |
|
public function has( $offset ) |
39
|
|
|
{ |
40
|
15 |
|
return $this->offsetExists( $offset ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public function getArrayCopy() |
48
|
|
|
{ |
49
|
20 |
|
return $this->data; |
50
|
|
|
} |
51
|
20 |
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @implements ArrayAccess |
55
|
|
|
*/ |
56
|
|
|
public function offsetExists($offset) |
57
|
|
|
{ |
58
|
|
|
return isset($this->data[ $offset ]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @implements ArrayAccess |
63
|
|
|
*/ |
64
|
|
|
public function offsetSet($offset, $value) |
65
|
15 |
|
{ |
66
|
|
|
$this->data[ $offset ] = $value; |
67
|
15 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @implements ArrayAccess |
71
|
|
|
*/ |
72
|
|
|
public function offsetGet($offset) |
73
|
|
|
{ |
74
|
|
|
return $this->offsetExists( $offset ) ? $this->data[ $offset ] : null; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @implements ArrayAccess |
79
|
|
|
*/ |
80
|
|
|
public function offsetUnset($offset) |
81
|
|
|
{ |
82
|
|
|
if ($this->offsetExists($offset)) { |
83
|
|
|
unset($this->data[ $offset ]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|