mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Merge remote-tracking branch 'igorw/feature/event-dispatcher' into develop
This commit is contained in:
commit
d60d9aa9d5
16 changed files with 263 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
||||||
/phpBB/cache/*.html
|
/phpBB/cache/*.html
|
||||||
/phpBB/cache/*.php
|
/phpBB/cache/*.php
|
||||||
/phpBB/cache/queue.php.lock
|
/phpBB/cache/queue.php.lock
|
||||||
|
/phpBB/composer.phar
|
||||||
/phpBB/config.php
|
/phpBB/config.php
|
||||||
/phpBB/config_dev.php
|
/phpBB/config_dev.php
|
||||||
/phpBB/config_test.php
|
/phpBB/config_test.php
|
||||||
|
@ -11,6 +12,7 @@
|
||||||
/phpBB/images/avatars/gallery/*
|
/phpBB/images/avatars/gallery/*
|
||||||
/phpBB/images/avatars/upload/*
|
/phpBB/images/avatars/upload/*
|
||||||
/phpBB/store/*
|
/phpBB/store/*
|
||||||
|
/phpBB/vendor
|
||||||
/tests/phpbb_unit_tests.sqlite2
|
/tests/phpbb_unit_tests.sqlite2
|
||||||
/tests/test_config.php
|
/tests/test_config.php
|
||||||
/tests/tmp/*
|
/tests/tmp/*
|
||||||
|
|
|
@ -13,6 +13,8 @@ before_script:
|
||||||
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS phpbb_tests;'; fi"
|
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS phpbb_tests;'; fi"
|
||||||
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.2' ]; then pear install --force phpunit/DbUnit; else pyrus install --force phpunit/DbUnit; fi"
|
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.2' ]; then pear install --force phpunit/DbUnit; else pyrus install --force phpunit/DbUnit; fi"
|
||||||
- phpenv rehash
|
- phpenv rehash
|
||||||
|
- curl -s http://getcomposer.org/installer | php
|
||||||
|
- php composer.phar install
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpunit --configuration travis/phpunit-$DB-travis.xml
|
- phpunit --configuration travis/phpunit-$DB-travis.xml
|
||||||
|
|
|
@ -8,6 +8,15 @@ phpBB is a free bulletin board written in PHP.
|
||||||
|
|
||||||
Find support and lots more on [phpBB.com](http://www.phpbb.com)! Discuss the development on [area51](http://area51.phpbb.com/phpBB/index.php).
|
Find support and lots more on [phpBB.com](http://www.phpbb.com)! Discuss the development on [area51](http://area51.phpbb.com/phpBB/index.php).
|
||||||
|
|
||||||
|
## INSTALLING DEPENDENCIES
|
||||||
|
|
||||||
|
To be able to run an installation from the repo (and not from a pre-built package) you need to run the following commands to install phpBB's dependencies.
|
||||||
|
|
||||||
|
cd phpBB
|
||||||
|
curl -s http://getcomposer.org/installer | php
|
||||||
|
php composer.phar install
|
||||||
|
|
||||||
|
|
||||||
## CONTRIBUTE
|
## CONTRIBUTE
|
||||||
|
|
||||||
1. [Create an account on phpBB.com](http://www.phpbb.com/community/ucp.php?mode=register)
|
1. [Create an account on phpBB.com](http://www.phpbb.com/community/ucp.php?mode=register)
|
||||||
|
|
|
@ -15,6 +15,8 @@ if (!defined('IN_PHPBB'))
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
|
|
||||||
require($phpbb_root_path . 'includes/startup.' . $phpEx);
|
require($phpbb_root_path . 'includes/startup.' . $phpEx);
|
||||||
|
|
||||||
if (file_exists($phpbb_root_path . 'config.' . $phpEx))
|
if (file_exists($phpbb_root_path . 'config.' . $phpEx))
|
||||||
|
@ -98,6 +100,7 @@ $phpbb_class_loader_ext->set_cache($cache->get_driver());
|
||||||
$phpbb_class_loader->set_cache($cache->get_driver());
|
$phpbb_class_loader->set_cache($cache->get_driver());
|
||||||
|
|
||||||
// Instantiate some basic classes
|
// Instantiate some basic classes
|
||||||
|
$phpbb_dispatcher = new phpbb_event_dispatcher();
|
||||||
$request = new phpbb_request();
|
$request = new phpbb_request();
|
||||||
$user = new user();
|
$user = new user();
|
||||||
$auth = new auth();
|
$auth = new auth();
|
||||||
|
@ -124,6 +127,9 @@ $phpbb_template_locator = new phpbb_template_locator();
|
||||||
$phpbb_template_path_provider = new phpbb_template_extension_path_provider($phpbb_extension_manager, new phpbb_template_path_provider());
|
$phpbb_template_path_provider = new phpbb_template_extension_path_provider($phpbb_extension_manager, new phpbb_template_path_provider());
|
||||||
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_template_locator, $phpbb_template_path_provider);
|
$template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_template_locator, $phpbb_template_path_provider);
|
||||||
|
|
||||||
|
$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
|
||||||
|
$phpbb_subscriber_loader->load();
|
||||||
|
|
||||||
// Add own hook handler
|
// Add own hook handler
|
||||||
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
||||||
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
|
$phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display')));
|
||||||
|
|
5
phpBB/composer.json
Normal file
5
phpBB/composer.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"symfony/event-dispatcher": "2.0.*"
|
||||||
|
}
|
||||||
|
}
|
10
phpBB/composer.lock
generated
Normal file
10
phpBB/composer.lock
generated
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"hash": "9bada3748ec2933fe0864dcfafbcd671",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"package": "symfony/event-dispatcher",
|
||||||
|
"version": "v2.0.10"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"aliases": []
|
||||||
|
}
|
|
@ -79,3 +79,6 @@ Pear (c) 2001-2004 PHP Group, http://pear.php.net
|
||||||
|
|
||||||
Text_Diff-0.2.1 http://pear.php.net/package/Text_Diff
|
Text_Diff-0.2.1 http://pear.php.net/package/Text_Diff
|
||||||
|
|
||||||
|
MIT licenced:
|
||||||
|
Symfony2 (c) 2004-2011 Fabien Potencier, http://symfony.com/
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ if (isset($_GET['avatar']))
|
||||||
$phpbb_class_loader_ext->set_cache($cache->get_driver());
|
$phpbb_class_loader_ext->set_cache($cache->get_driver());
|
||||||
$phpbb_class_loader->set_cache($cache->get_driver());
|
$phpbb_class_loader->set_cache($cache->get_driver());
|
||||||
|
|
||||||
|
$phpbb_dispatcher = new phpbb_event_dispatcher();
|
||||||
$request = new phpbb_request();
|
$request = new phpbb_request();
|
||||||
$db = new $sql_db();
|
$db = new $sql_db();
|
||||||
|
|
||||||
|
@ -78,6 +79,9 @@ if (isset($_GET['avatar']))
|
||||||
// load extensions
|
// load extensions
|
||||||
$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver());
|
$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver());
|
||||||
|
|
||||||
|
$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
|
||||||
|
$phpbb_subscriber_loader->load();
|
||||||
|
|
||||||
$filename = request_var('avatar', '');
|
$filename = request_var('avatar', '');
|
||||||
$avatar_group = false;
|
$avatar_group = false;
|
||||||
$exit = false;
|
$exit = false;
|
||||||
|
|
68
phpBB/includes/event/data.php
Normal file
68
phpBB/includes/event/data.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2012 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]);
|
||||||
|
}
|
||||||
|
}
|
42
phpBB/includes/event/dispatcher.php
Normal file
42
phpBB/includes/event/dispatcher.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2012 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\EventDispatcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension of the Symfony2 EventDispatcher
|
||||||
|
*
|
||||||
|
* It provides an additional `trigger_event` method, which
|
||||||
|
* gives some syntactic sugar for dispatching events. Instead
|
||||||
|
* of creating the event object, the method will do that for
|
||||||
|
* you.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* $vars = array('page_title');
|
||||||
|
* extract($phpbb_dispatcher->trigger_event('core.index', compact($vars)));
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class phpbb_event_dispatcher extends EventDispatcher
|
||||||
|
{
|
||||||
|
public function trigger_event($eventName, $data = array())
|
||||||
|
{
|
||||||
|
$event = new phpbb_event_data($data);
|
||||||
|
$this->dispatch($eventName, $event);
|
||||||
|
return $event->get_data_filtered(array_keys($data));
|
||||||
|
}
|
||||||
|
}
|
46
phpBB/includes/event/extension_subscriber_loader.php
Normal file
46
phpBB/includes/event/extension_subscriber_loader.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package phpBB3
|
||||||
|
* @copyright (c) 2012 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\EventDispatcherInterface;
|
||||||
|
|
||||||
|
class phpbb_event_extension_subscriber_loader
|
||||||
|
{
|
||||||
|
private $dispatcher;
|
||||||
|
private $extension_manager;
|
||||||
|
|
||||||
|
public function __construct(EventDispatcherInterface $dispatcher, phpbb_extension_manager $extension_manager)
|
||||||
|
{
|
||||||
|
$this->dispatcher = $dispatcher;
|
||||||
|
$this->extension_manager = $extension_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load()
|
||||||
|
{
|
||||||
|
$finder = $this->extension_manager->get_finder();
|
||||||
|
$subscriber_classes = $finder
|
||||||
|
->extension_directory('/event')
|
||||||
|
->suffix('listener')
|
||||||
|
->core_path('event/')
|
||||||
|
->get_classes();
|
||||||
|
|
||||||
|
foreach ($subscriber_classes as $class)
|
||||||
|
{
|
||||||
|
$subscriber = new $class();
|
||||||
|
$this->dispatcher->addSubscriber($subscriber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4478,6 +4478,7 @@ function phpbb_http_login($param)
|
||||||
function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum')
|
function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum')
|
||||||
{
|
{
|
||||||
global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path;
|
global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path;
|
||||||
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
if (defined('HEADER_INC'))
|
if (defined('HEADER_INC'))
|
||||||
{
|
{
|
||||||
|
@ -4761,6 +4762,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
||||||
'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
|
'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$vars = array('page_title', 'display_online_list', 'item_id', 'item');
|
||||||
|
extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars)));
|
||||||
|
|
||||||
// application/xhtml+xml not used because of IE
|
// application/xhtml+xml not used because of IE
|
||||||
header('Content-type: text/html; charset=UTF-8');
|
header('Content-type: text/html; charset=UTF-8');
|
||||||
|
|
||||||
|
|
|
@ -147,5 +147,36 @@ if (function_exists('date_default_timezone_set') && function_exists('date_defaul
|
||||||
date_default_timezone_set(@date_default_timezone_get());
|
date_default_timezone_set(@date_default_timezone_get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Autoloading of dependencies.
|
||||||
|
// Three options are supported:
|
||||||
|
// 1. If dependencies are installed with Composer, Composer will create a
|
||||||
|
// vendor/.composer/autoload.php. If this file exists it will be
|
||||||
|
// automatically used by phpBB. This is the default mode that phpBB
|
||||||
|
// will use when shipped.
|
||||||
|
// 2. To disable composer autoloading, PHPBB_NO_COMPOSER_AUTOLOAD can be specified.
|
||||||
|
// Additionally specify PHPBB_AUTOLOAD=/path/to/autoload.php in the
|
||||||
|
// environment. This is useful for running CLI scripts and tests.
|
||||||
|
// /path/to/autoload.php should define and register class loaders
|
||||||
|
// for all of phpBB's dependencies.
|
||||||
|
// 3. You can also set PHPBB_NO_COMPOSER_AUTOLOAD without setting PHPBB_AUTOLOAD.
|
||||||
|
// In this case autoloading needs to be defined before running any phpBB
|
||||||
|
// script. This might be useful in cases when phpBB is integrated into a
|
||||||
|
// larger program.
|
||||||
|
if (getenv('PHPBB_NO_COMPOSER_AUTOLOAD'))
|
||||||
|
{
|
||||||
|
if (getenv('PHPBB_AUTOLOAD'))
|
||||||
|
{
|
||||||
|
require(getenv('PHPBB_AUTOLOAD'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!file_exists($phpbb_root_path . 'vendor/.composer/autoload.php'))
|
||||||
|
{
|
||||||
|
trigger_error('You have not set up composer dependencies. See http://getcomposer.org/.', E_USER_ERROR);
|
||||||
|
}
|
||||||
|
require($phpbb_root_path . 'vendor/.composer/autoload.php');
|
||||||
|
}
|
||||||
|
|
||||||
$starttime = explode(' ', microtime());
|
$starttime = explode(' ', microtime());
|
||||||
$starttime = $starttime[1] + $starttime[0];
|
$starttime = $starttime[1] + $starttime[0];
|
||||||
|
|
|
@ -120,6 +120,7 @@ $cache = $cache_factory->get_service();
|
||||||
$phpbb_class_loader_ext->set_cache($cache->get_driver());
|
$phpbb_class_loader_ext->set_cache($cache->get_driver());
|
||||||
$phpbb_class_loader->set_cache($cache->get_driver());
|
$phpbb_class_loader->set_cache($cache->get_driver());
|
||||||
|
|
||||||
|
$phpbb_dispatcher = new phpbb_event_dispatcher();
|
||||||
$request = new phpbb_request();
|
$request = new phpbb_request();
|
||||||
$user = new user();
|
$user = new user();
|
||||||
$db = new $sql_db();
|
$db = new $sql_db();
|
||||||
|
|
|
@ -92,6 +92,7 @@ $cache = $cache_factory->get_service();
|
||||||
$phpbb_class_loader_ext->set_cache($cache->get_driver());
|
$phpbb_class_loader_ext->set_cache($cache->get_driver());
|
||||||
$phpbb_class_loader->set_cache($cache->get_driver());
|
$phpbb_class_loader->set_cache($cache->get_driver());
|
||||||
|
|
||||||
|
$phpbb_dispatcher = new phpbb_event_dispatcher();
|
||||||
$request = new phpbb_request();
|
$request = new phpbb_request();
|
||||||
|
|
||||||
// make sure request_var uses this request instance
|
// make sure request_var uses this request instance
|
||||||
|
|
29
tests/event/dispatcher_test.php
Normal file
29
tests/event/dispatcher_test.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2012 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_event_dispatcher_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
public function test_trigger_event()
|
||||||
|
{
|
||||||
|
$dispatcher = new phpbb_event_dispatcher();
|
||||||
|
|
||||||
|
$dispatcher->addListener('core.test_event', function (phpbb_event_data $event) {
|
||||||
|
$event['foo'] = $event['foo'] . '2';
|
||||||
|
$event['bar'] = $event['bar'] . '2';
|
||||||
|
});
|
||||||
|
|
||||||
|
$foo = 'foo';
|
||||||
|
$bar = 'bar';
|
||||||
|
|
||||||
|
$vars = array('foo', 'bar');
|
||||||
|
$result = $dispatcher->trigger_event('core.test_event', compact($vars));
|
||||||
|
|
||||||
|
$this->assertSame(array('foo' => 'foo2', 'bar' => 'bar2'), $result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue