1 | <?php |
||
12 | class ValueBag |
||
13 | { |
||
14 | /** |
||
15 | * @param array $bag |
||
16 | */ |
||
17 | public function __construct(array $bag = []) |
||
21 | |||
22 | /** |
||
23 | * @param array $bag |
||
24 | */ |
||
25 | public function add(array $bag = []) |
||
29 | |||
30 | /** |
||
31 | * Returns true if the parameter is defined. |
||
32 | * |
||
33 | * @param string $key The key |
||
34 | * |
||
35 | * @return bool true if the parameter exists, false otherwise |
||
36 | */ |
||
37 | public function has($key) |
||
41 | |||
42 | /** |
||
43 | * Returns the parameter keys. |
||
44 | * |
||
45 | * @return array An array of parameter keys |
||
46 | */ |
||
47 | public function keys() |
||
51 | |||
52 | /** |
||
53 | * Returns a parameter by name. |
||
54 | * |
||
55 | * @param string $key |
||
56 | * @param mixed|null $default The default value if the parameter key does not exist |
||
57 | * |
||
58 | * @return mixed|null |
||
59 | */ |
||
60 | public function fetch($key, $default = null) |
||
64 | |||
65 | /** |
||
66 | * Returns the bag value converted to integer. |
||
67 | * |
||
68 | * @param string $key |
||
69 | * @param int $default The default value if the parameter key does not exist |
||
70 | * |
||
71 | * @return int |
||
72 | */ |
||
73 | public function fetchInt($key, $default = 0) |
||
77 | |||
78 | /** |
||
79 | * Returns the bag value converted to float with precision. |
||
80 | * |
||
81 | * @param string $key |
||
82 | * @param float $default The default value if the parameter key does not exist |
||
83 | * @param int $precision The optional number of decimal digits to round to |
||
84 | * @return float |
||
85 | */ |
||
86 | public function fetchFloat($key, $default = 0.0, $precision = 2) |
||
90 | |||
91 | /** |
||
92 | * Returns the bag value converted to boolean. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @param bool|false $default The default value if the parameter key does not exist |
||
96 | * @return mixed |
||
97 | */ |
||
98 | public function fetchBool($key, $default = false) |
||
102 | |||
103 | /** |
||
104 | * Filter value. |
||
105 | * |
||
106 | * @param string $key |
||
107 | * @param mixed|null $default The default value if the parameter key does not exist |
||
108 | * @param int $filter FILTER_* constant |
||
109 | * @param array $options Filter options |
||
110 | * |
||
111 | * @see http://php.net/manual/en/function.filter-var.php |
||
112 | * |
||
113 | * @return mixed |
||
114 | */ |
||
115 | public function fetchFilter($key, $default = null, $filter = FILTER_DEFAULT, $options = []) |
||
129 | |||
130 | /** |
||
131 | * Use custom function to process value. |
||
132 | * |
||
133 | * @param string $key |
||
134 | * @param callable $callback |
||
135 | * @param mixed|null $default |
||
136 | * |
||
137 | * @return mixed |
||
138 | */ |
||
139 | public function fetchCustom($key, $callback, $default = null) |
||
143 | |||
144 | /** |
||
145 | * Use mysql escape function. |
||
146 | * |
||
147 | * @param $key |
||
148 | * @param \mysqli $db |
||
149 | * @param string $default |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function fetchEscape($key, \mysqli $db, $default = '') |
||
157 | |||
158 | /** |
||
159 | * Returns the number of values. |
||
160 | * |
||
161 | * @return int |
||
162 | */ |
||
163 | public function count() |
||
167 | |||
168 | protected $bag; |
||
169 | } |