-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathParameterBag.php
104 lines (89 loc) · 1.88 KB
/
ParameterBag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php // phpcs:ignore WordPress.Files.FileName
/**
* Parameter bag class.
*
* @package rabbit-framework
* @author Sematico LTD <[email protected]>
* @copyright 2020 Sematico LTD
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0-or-later
* @link https://sematico.com
*/
namespace Rabbit\Utils;
use Rabbit\Contracts\ParameterBagInterface;
/**
* Agnostic implementation of the Symfony HttpFoundation ParameterBag.
*/
class ParameterBag implements ParameterBagInterface {
/**
* @var array
*/
private $parameters;
/**
* Constructor
*
* @param array $parameters
*/
public function __construct( array $parameters = [] ) {
$this->parameters = $parameters;
}
/**
* {@inheritdoc}
*/
public function add( array $parameters ) {
$this->parameters = array_merge( $this->parameters, $parameters );
}
/**
* {@inheritdoc}
*/
public function all(): array {
return $this->parameters;
}
/**
* {@inheritdoc}
*/
public function count() {
return count( $this->parameters );
}
/**
* {@inheritdoc}
*/
public function get( $parameter, $default = null ) {
return $this->has( $parameter ) ? $this->parameters[ $parameter ] : $default;
}
/**
* {@inheritdoc}
*/
public function getIterator() {
return new \ArrayIterator( $this->parameters );
}
/**
* {@inheritdoc}
*/
public function has( $parameter ): bool {
return array_key_exists( $parameter, $this->parameters );
}
/**
* {@inheritdoc}
*/
public function keys(): array {
return array_keys( $this->parameters );
}
/**
* {@inheritdoc}
*/
public function remove( $parameter ) {
unset( $this->parameters[ $parameter ] );
}
/**
* {@inheritdoc}
*/
public function replace( array $parameters ) {
$this->parameters = $parameters;
}
/**
* {@inheritdoc}
*/
public function set( $parameter, $value = null ) {
$this->parameters[ $parameter ] = $value;
}
}