diff --git a/.gitignore b/.gitignore index e6e017f85e..4093aeb56d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /phpBB/cache/*.html /phpBB/cache/*.php /phpBB/cache/queue.php.lock +/phpBB/composer.phar /phpBB/config.php /phpBB/config_dev.php /phpBB/config_test.php @@ -11,6 +12,7 @@ /phpBB/images/avatars/gallery/* /phpBB/images/avatars/upload/* /phpBB/store/* +/phpBB/vendor /tests/phpbb_unit_tests.sqlite2 /tests/test_config.php /tests/tmp/* diff --git a/.travis.yml b/.travis.yml index d5e1231584..f21928dd37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 [ '$TRAVIS_PHP_VERSION' = '5.2' ]; then pear install --force phpunit/DbUnit; else pyrus install --force phpunit/DbUnit; fi" - phpenv rehash + - curl -s http://getcomposer.org/installer | php + - php composer.phar install script: - phpunit --configuration travis/phpunit-$DB-travis.xml diff --git a/README.md b/README.md index 51e65176c6..a7feb8db40 100644 --- a/README.md +++ b/README.md @@ -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). +## 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 1. [Create an account on phpBB.com](http://www.phpbb.com/community/ucp.php?mode=register) diff --git a/phpBB/common.php b/phpBB/common.php index 8e149fef57..129f7e4881 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\EventDispatcher\EventDispatcher; + require($phpbb_root_path . 'includes/startup.' . $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()); // Instantiate some basic classes +$phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); $user = new user(); $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()); $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 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'))); diff --git a/phpBB/composer.json b/phpBB/composer.json new file mode 100644 index 0000000000..1059b97f84 --- /dev/null +++ b/phpBB/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "symfony/event-dispatcher": "2.0.*" + } +} diff --git a/phpBB/composer.lock b/phpBB/composer.lock new file mode 100644 index 0000000000..062ad4b3aa --- /dev/null +++ b/phpBB/composer.lock @@ -0,0 +1,10 @@ +{ + "hash": "9bada3748ec2933fe0864dcfafbcd671", + "packages": [ + { + "package": "symfony/event-dispatcher", + "version": "v2.0.10" + } + ], + "aliases": [] +} diff --git a/phpBB/docs/AUTHORS b/phpBB/docs/AUTHORS index 4fe0af6e28..8be261706e 100644 --- a/phpBB/docs/AUTHORS +++ b/phpBB/docs/AUTHORS @@ -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 +MIT licenced: +Symfony2 (c) 2004-2011 Fabien Potencier, http://symfony.com/ + diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 2baa9d6c8a..c01b0789de 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -56,6 +56,7 @@ if (isset($_GET['avatar'])) $phpbb_class_loader_ext->set_cache($cache->get_driver()); $phpbb_class_loader->set_cache($cache->get_driver()); + $phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); $db = new $sql_db(); @@ -78,6 +79,9 @@ if (isset($_GET['avatar'])) // load extensions $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', ''); $avatar_group = false; $exit = false; diff --git a/phpBB/includes/event/data.php b/phpBB/includes/event/data.php new file mode 100644 index 0000000000..70718ff0ae --- /dev/null +++ b/phpBB/includes/event/data.php @@ -0,0 +1,68 @@ +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]); + } +} diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/includes/event/dispatcher.php new file mode 100644 index 0000000000..2bf46b9b06 --- /dev/null +++ b/phpBB/includes/event/dispatcher.php @@ -0,0 +1,42 @@ +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)); + } +} diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php new file mode 100644 index 0000000000..d933b943d7 --- /dev/null +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -0,0 +1,46 @@ +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); + } + } +} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9913a80a70..7a96dd3609 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4478,6 +4478,7 @@ function phpbb_http_login($param) 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 $phpbb_dispatcher; 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')), )); + $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 header('Content-type: text/html; charset=UTF-8'); diff --git a/phpBB/includes/startup.php b/phpBB/includes/startup.php index fc45cd882b..f75d70e366 100644 --- a/phpBB/includes/startup.php +++ b/phpBB/includes/startup.php @@ -147,5 +147,36 @@ if (function_exists('date_default_timezone_set') && function_exists('date_defaul 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 = $starttime[1] + $starttime[0]; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 8a7ec1004e..25b6387485 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -120,6 +120,7 @@ $cache = $cache_factory->get_service(); $phpbb_class_loader_ext->set_cache($cache->get_driver()); $phpbb_class_loader->set_cache($cache->get_driver()); +$phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); $user = new user(); $db = new $sql_db(); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index f180511e46..a196a429e4 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -92,6 +92,7 @@ $cache = $cache_factory->get_service(); $phpbb_class_loader_ext->set_cache($cache->get_driver()); $phpbb_class_loader->set_cache($cache->get_driver()); +$phpbb_dispatcher = new phpbb_event_dispatcher(); $request = new phpbb_request(); // make sure request_var uses this request instance diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php new file mode 100644 index 0000000000..f8fe060d99 --- /dev/null +++ b/tests/event/dispatcher_test.php @@ -0,0 +1,29 @@ +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); + } +}