Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
55.56% |
5 / 9 |
|
55.56% |
5 / 9 |
CRAP | |
0.00% |
0 / 1 |
data | |
55.56% |
5 / 9 |
|
55.56% |
5 / 9 |
18.78 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
set_data | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
get_data | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_data_filtered | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
offsetExists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
offsetGet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
offsetSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
offsetUnset | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
update_subarray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\event; |
15 | |
16 | use Symfony\Contracts\EventDispatcher\Event; |
17 | |
18 | class data extends Event implements \ArrayAccess |
19 | { |
20 | private $data; |
21 | |
22 | public function __construct(array $data = array()) |
23 | { |
24 | $this->set_data($data); |
25 | } |
26 | |
27 | public function set_data(array $data = array()) |
28 | { |
29 | $this->data = $data; |
30 | } |
31 | |
32 | public function get_data() |
33 | { |
34 | return $this->data; |
35 | } |
36 | |
37 | /** |
38 | * Returns data filtered to only include specified keys. |
39 | * |
40 | * This effectively discards any keys added to data by hooks. |
41 | */ |
42 | public function get_data_filtered($keys) |
43 | { |
44 | return array_intersect_key($this->data, array_flip($keys)); |
45 | } |
46 | |
47 | #[\ReturnTypeWillChange] |
48 | public function offsetExists($offset) |
49 | { |
50 | return isset($this->data[$offset]); |
51 | } |
52 | |
53 | #[\ReturnTypeWillChange] |
54 | public function offsetGet($offset) |
55 | { |
56 | return isset($this->data[$offset]) ? $this->data[$offset] : null; |
57 | } |
58 | |
59 | #[\ReturnTypeWillChange] |
60 | public function offsetSet($offset, $value) |
61 | { |
62 | $this->data[$offset] = $value; |
63 | } |
64 | |
65 | #[\ReturnTypeWillChange] |
66 | public function offsetUnset($offset) |
67 | { |
68 | unset($this->data[$offset]); |
69 | } |
70 | |
71 | /** |
72 | * Returns data with updated key in specified offset. |
73 | * |
74 | * @param string $subarray Data array subarray |
75 | * @param string $key Subarray key |
76 | * @param mixed $value Value to update |
77 | */ |
78 | public function update_subarray($subarray, $key, $value) |
79 | { |
80 | $this->data[$subarray][$key] = $value; |
81 | } |
82 | } |