Permalink
Browse files

[feature/event-dispatcher] Allow subscribers to be loaded from extens…

…ions

PHPBB3-9550
  • Loading branch information...
1 parent 80840a5 commit 581b5624f7be3675a35fc61ca6b67b409ae6e8c6 @igorw committed Jan 7, 2012
Showing with 47 additions and 0 deletions.
  1. +4 −0 phpBB/common.php
  2. +43 −0 phpBB/includes/event/extension_subscriber_loader.php
View
@@ -98,6 +98,7 @@
$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 +125,9 @@
$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')));
@@ -0,0 +1,43 @@
+<?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;
+}
+
+class phpbb_event_extension_subscriber_loader
+{
+ private $dispatcher;
+ private $extension_manager;
+
+ public function __construct(phpbb_event_dispatcher $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('subscriber')
+ ->core_path('event/')
+ ->get_classes();
+
+ foreach ($subscriber_classes as $class) {
+ $subscriber = new $class();
+ $this->dispatcher->add_subscriber($subscriber);
+ }
+ }
+}

0 comments on commit 581b562

Please sign in to comment.