Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14707183
D9262.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D9262.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1288,6 +1288,7 @@
'PhabricatorAuthUnlinkController' => 'applications/auth/controller/PhabricatorAuthUnlinkController.php',
'PhabricatorAuthValidateController' => 'applications/auth/controller/PhabricatorAuthValidateController.php',
'PhabricatorAuthenticationConfigOptions' => 'applications/config/option/PhabricatorAuthenticationConfigOptions.php',
+ 'PhabricatorAutoEventListener' => 'infrastructure/events/PhabricatorAutoEventListener.php',
'PhabricatorBarePageExample' => 'applications/uiexample/examples/PhabricatorBarePageExample.php',
'PhabricatorBarePageView' => 'view/page/PhabricatorBarePageView.php',
'PhabricatorBaseEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBaseEnglishTranslation.php',
@@ -4062,6 +4063,7 @@
'PhabricatorAuthUnlinkController' => 'PhabricatorAuthController',
'PhabricatorAuthValidateController' => 'PhabricatorAuthController',
'PhabricatorAuthenticationConfigOptions' => 'PhabricatorApplicationConfigOptions',
+ 'PhabricatorAutoEventListener' => 'PhabricatorEventListener',
'PhabricatorBarePageExample' => 'PhabricatorUIExample',
'PhabricatorBarePageView' => 'AphrontPageView',
'PhabricatorBaseEnglishTranslation' => 'PhabricatorTranslation',
diff --git a/src/infrastructure/events/PhabricatorAutoEventListener.php b/src/infrastructure/events/PhabricatorAutoEventListener.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/events/PhabricatorAutoEventListener.php
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * Event listener which is registered automatically, without requiring
+ * configuration.
+ *
+ * Normally, event listeners must be registered via applications. This is
+ * appropriate for structured listeners in libraries, but it adds a lot of
+ * overhead and is cumbersome for one-off listeners.
+ *
+ * All concrete subclasses of this class are automatically registered at
+ * startup. This allows it to be used with custom one-offs that can be dropped
+ * into `phabricator/src/extensions/`.
+ */
+abstract class PhabricatorAutoEventListener extends PhabricatorEventListener {
+
+}
diff --git a/src/infrastructure/events/PhabricatorEventEngine.php b/src/infrastructure/events/PhabricatorEventEngine.php
--- a/src/infrastructure/events/PhabricatorEventEngine.php
+++ b/src/infrastructure/events/PhabricatorEventEngine.php
@@ -1,36 +1,50 @@
<?php
-/**
- * @group events
- */
final class PhabricatorEventEngine {
public static function initialize() {
- $listeners = PhabricatorEnv::getEnvConfig('events.listeners');
- foreach ($listeners as $listener) {
+ // NOTE: If any of this fails, we just log it and move on. It's important
+ // to try to make it through here because users may have difficulty fixing
+ // fix the errors if we don't: for example, if we fatal here a user may not
+ // be able to run `bin/config` in order to remove an invalid listener.
+
+ // Load automatic listeners.
+ $listeners = id(new PhutilSymbolLoader())
+ ->setAncestorClass('PhabricatorAutoEventListener')
+ ->loadObjects();
+
+ // Load configured listeners.
+ $config_listeners = PhabricatorEnv::getEnvConfig('events.listeners');
+ foreach ($config_listeners as $listener_class) {
try {
- id(new $listener())->register();
+ $listeners[] = newv($listener_class, array());
} catch (Exception $ex) {
- // If the listener does not exist, or throws when registering, just
- // log it and continue. In particular, this is important to let you
- // run `bin/config` in order to remove an invalid listener.
phlog($ex);
}
}
- // Register the DarkConosole event logger.
- id(new DarkConsoleEventPluginAPI())->register();
- id(new ManiphestEdgeEventListener())->register();
+ // Add builtin listeners.
+ $listeners[] = new DarkConsoleEventPluginAPI();
+ $listeners[] = new ManiphestEdgeEventListener();
+ // Add application listeners.
$applications = PhabricatorApplication::getAllInstalledApplications();
foreach ($applications as $application) {
- $listeners = $application->getEventListeners();
- foreach ($listeners as $listener) {
+ $app_listeners = $application->getEventListeners();
+ foreach ($app_listeners as $listener) {
$listener->setApplication($application);
- $listener->register();
+ $listeners[] = $listener;
}
}
+ // Now, register all of the listeners.
+ foreach ($listeners as $listener) {
+ try {
+ $listener->register();
+ } catch (Exception $ex) {
+ phlog($ex);
+ }
+ }
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 18, 4:40 AM (6 h, 56 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7000252
Default Alt Text
D9262.id.diff (4 KB)
Attached To
Mode
D9262: Make it much easier to add one-off event listeners
Attached
Detach File
Event Timeline
Log In to Comment