1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-25 04:23:38 +01:00
Oleg Pudeyev be23445b8c [feature/event-dispatcher] Add get_data_filtered function to event data.
Its purpose is to discard any keys added by hooks to data stored
in the event, such that only keys that the ledge knows how to handle
are processed.

PHPBB3-9550
2012-03-18 02:48:55 -04:00

69 lines
1.3 KiB
PHP

<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
use Symfony\Component\EventDispatcher\Event;
class phpbb_event_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]);
}
}