aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/event/data.php
blob: 3481023b74b1402a4ab18bd1d25bbc640f84f272 (plain)
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
<?php
/**
*
* @package phpBB3
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

namespace phpbb\event;

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
    exit;
}

use Symfony\Component\EventDispatcher\Event;

class data extends Event implements \ArrayAccess
{
    private $data;

    public function __construct(array $data = array())
    {
        $this->set_data($data);
    }

    public function set_data(array $data = array())
    {
        $this->data = $data;
    }

    public function get_data()
    {
        return $this->data;
    }

    /**
     * Returns data filtered to only include specified keys.
     *
     * This effectively discards any keys added to data by hooks.
     */
    public function get_data_filtered($keys)
    {
        return array_intersect_key($this->data, array_flip($keys));
    }

    public function offsetExists($offset)
    {
        return isset($this->data[$offset]);
    }

    public function offsetGet($offset)
    {
        return isset($this->data[$offset]) ? $this->data[$offset] : null;
    }

    public function offsetSet($offset, $value)
    {
        $this->data[$offset] = $value;
    }

    public function offsetUnset($offset)
    {
        unset($this->data[$offset]);
    }
}