Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions libraries/src/Application/AdministratorApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

use Joomla\Application\Web\WebClient;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\AfterDispatchEvent;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Event\Application\AfterRouteEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Input\Input;
Expand Down Expand Up @@ -149,7 +151,10 @@ public function dispatch($component = null)
$document->setBuffer($contents, ['type' => 'component']);

// Trigger the onAfterDispatch event.
$this->triggerEvent('onAfterDispatch');
$this->dispatchEvent(
'onAfterDispatch',
new AfterDispatchEvent('onAfterDispatch', ['subject' => $this])
);
}

/**
Expand Down Expand Up @@ -454,8 +459,11 @@ protected function route()
$this->isHandlingMultiFactorAuthentication();

// Trigger the onAfterRoute event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterRoute');
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterRoute',
new AfterRouteEvent('onAfterRoute', ['subject' => $this])
);
}

/**
Expand Down
22 changes: 18 additions & 4 deletions libraries/src/Application/ApiApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
use Joomla\Application\Web\WebClient;
use Joomla\CMS\Access\Exception\AuthenticationFailed;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\AfterApiRouteEvent;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Event\Application\AfterDispatchEvent;
use Joomla\CMS\Event\Application\BeforeApiRouteEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\ApiRouter;
Expand Down Expand Up @@ -228,8 +231,12 @@ protected function route()
$router = $this->getContainer()->get(ApiRouter::class);

// Trigger the onBeforeApiRoute event.
PluginHelper::importPlugin('webservices');
$this->triggerEvent('onBeforeApiRoute', [&$router, $this]);
PluginHelper::importPlugin('webservices', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onBeforeApiRoute',
new BeforeApiRouteEvent('onBeforeApiRoute', ['router' => $router, 'subject' => $this])
);

$caught404 = false;
$method = $this->input->getMethod();

Expand Down Expand Up @@ -300,7 +307,10 @@ protected function route()
}
}

$this->triggerEvent('onAfterApiRoute', [$this]);
$this->dispatchEvent(
'onAfterApiRoute',
new AfterApiRouteEvent('onAfterApiRoute', ['subject' => $this])
);

if (!isset($route['vars']['public']) || $route['vars']['public'] === false) {
if (!$this->login(['username' => ''], ['silent' => true, 'action' => 'core.login.api'])) {
Expand Down Expand Up @@ -414,6 +424,7 @@ public function dispatch($component = null)
$document = Factory::getDocument();

// Trigger the onAfterInitialiseDocument event.
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterInitialiseDocument',
new AfterInitialiseDocumentEvent('onAfterInitialiseDocument', ['subject' => $this, 'document' => $document])
Expand All @@ -423,6 +434,9 @@ public function dispatch($component = null)
$document->setBuffer($contents, ['type' => 'component']);

// Trigger the onAfterDispatch event.
$this->triggerEvent('onAfterDispatch');
$this->dispatchEvent(
'onAfterDispatch',
new AfterDispatchEvent('onAfterDispatch', ['subject' => $this])
);
}
}
61 changes: 43 additions & 18 deletions libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
use Joomla\Application\SessionAwareWebApplicationTrait;
use Joomla\Application\Web\WebClient;
use Joomla\CMS\Authentication\Authentication;
use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Event\Application\AfterCompressEvent;
use Joomla\CMS\Event\Application\AfterInitialiseEvent;
use Joomla\CMS\Event\Application\AfterRenderEvent;
use Joomla\CMS\Event\Application\AfterRespondEvent;
use Joomla\CMS\Event\Application\AfterRouteEvent;
use Joomla\CMS\Event\Application\BeforeRenderEvent;
use Joomla\CMS\Event\Application\BeforeRespondEvent;
use Joomla\CMS\Event\ErrorEvent;
use Joomla\CMS\Exception\ExceptionHandler;
use Joomla\CMS\Extension\ExtensionManagerTrait;
Expand Down Expand Up @@ -303,33 +309,40 @@ public function execute()
$this->compress();

// Trigger the onAfterCompress event.
$this->triggerEvent('onAfterCompress');
$this->dispatchEvent(
'onAfterCompress',
new AfterCompressEvent('onAfterCompress', ['subject' => $this])
);
}
} catch (\Throwable $throwable) {
/** @var ErrorEvent $event */
$event = AbstractEvent::create(
$event = new ErrorEvent(
'onError',
[
'subject' => $throwable,
'eventClass' => ErrorEvent::class,
'application' => $this,
]
);

// Trigger the onError event.
$this->triggerEvent('onError', $event);
$this->dispatchEvent('onError', $event);

ExceptionHandler::handleException($event->getError());
}

// Trigger the onBeforeRespond event.
$this->getDispatcher()->dispatch('onBeforeRespond');
$this->dispatchEvent(
'onBeforeRespond',
new BeforeRespondEvent('onBeforeRespond', ['subject' => $this])
);

// Send the application response.
$this->respond();

// Trigger the onAfterRespond event.
$this->getDispatcher()->dispatch('onAfterRespond');
$this->dispatchEvent(
'onAfterRespond',
new AfterRespondEvent('onAfterRespond', ['subject' => $this])
);
}

/**
Expand Down Expand Up @@ -738,11 +751,14 @@ protected function initialiseApp($options = [])
$this->set('editor', $editor);

// Load the behaviour plugins
PluginHelper::importPlugin('behaviour');
PluginHelper::importPlugin('behaviour', null, true, $this->getDispatcher());

// Trigger the onAfterInitialise event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterInitialise');
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterInitialise',
new AfterInitialiseEvent('onAfterInitialise', ['subject' => $this])
);
}

/**
Expand Down Expand Up @@ -822,7 +838,7 @@ public function login($credentials, $options = [])
$response = $authenticate->authenticate($credentials, $options);

// Import the user plugin group.
PluginHelper::importPlugin('user');
PluginHelper::importPlugin('user', null, true, $this->getDispatcher());

if ($response->status === Authentication::STATUS_SUCCESS) {
/*
Expand Down Expand Up @@ -939,7 +955,7 @@ public function logout($userid = null, $options = [])
}

// Import the user plugin group.
PluginHelper::importPlugin('user');
PluginHelper::importPlugin('user', null, true, $this->getDispatcher());

// OK, the credentials are built. Lets fire the onLogout event.
$results = $this->triggerEvent('onUserLogout', [$parameters, $options]);
Expand Down Expand Up @@ -1012,8 +1028,11 @@ protected function render()
$this->document->parse($this->docOptions);

// Trigger the onBeforeRender event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onBeforeRender');
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onBeforeRender',
new BeforeRenderEvent('onBeforeRender', ['subject' => $this])
);

$caching = false;

Expand All @@ -1028,7 +1047,10 @@ protected function render()
$this->setBody($data);

// Trigger the onAfterRender event.
$this->triggerEvent('onAfterRender');
$this->dispatchEvent(
'onAfterRender',
new AfterRenderEvent('onAfterRender', ['subject' => $this])
);

// Mark afterRender in the profiler.
JDEBUG ? $this->profiler->mark('afterRender') : null;
Expand Down Expand Up @@ -1098,8 +1120,11 @@ protected function route()
}

// Trigger the onAfterRoute event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterRoute');
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterRoute',
new AfterRouteEvent('onAfterRoute', ['subject' => $this])
);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions libraries/src/Application/CliApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Joomla\CMS\Application\CLI\CliInput;
use Joomla\CMS\Application\CLI\CliOutput;
use Joomla\CMS\Application\CLI\Output\Stdout;
use Joomla\CMS\Event\Application\AfterExecuteEvent;
use Joomla\CMS\Event\Application\BeforeExecuteEvent;
use Joomla\CMS\Extension\ExtensionManagerTrait;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Language;
Expand Down Expand Up @@ -257,13 +259,19 @@ public function execute()
$this->createExtensionNamespaceMap();

// Trigger the onBeforeExecute event
$this->triggerEvent('onBeforeExecute');
$this->dispatchEvent(
'onBeforeExecute',
new BeforeExecuteEvent('onBeforeExecute', ['subject' => $this, 'container' => $this->getContainer()])
);

// Perform application routines.
$this->doExecute();

// Trigger the onAfterExecute event.
$this->triggerEvent('onAfterExecute');
$this->dispatchEvent(
'onAfterExecute',
new AfterExecuteEvent('onAfterExecute', ['subject' => $this])
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/src/Application/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ public function execute()
$this->populateHttpHost();

// Import CMS plugin groups to be able to subscribe to events
PluginHelper::importPlugin('system');
PluginHelper::importPlugin('console');
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
PluginHelper::importPlugin('console', null, true, $this->getDispatcher());

parent::execute();
}
Expand Down
27 changes: 23 additions & 4 deletions libraries/src/Application/DaemonApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

namespace Joomla\CMS\Application;

use Joomla\CMS\Event\Application\AfterExecuteEvent;
use Joomla\CMS\Event\Application\BeforeExecuteEvent;
use Joomla\CMS\Event\Application\DeamonForkEvent;
use Joomla\CMS\Event\Application\DeamonReceiveSignalEvent;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Input\Cli;
use Joomla\CMS\Log\Log;
Expand Down Expand Up @@ -163,7 +167,13 @@ public static function signal($signal)
}

// Fire the onReceiveSignal event.
static::$instance->triggerEvent('onReceiveSignal', [$signal]);
static::$instance->getDispatcher()->dispatch(
'onReceiveSignal',
new DeamonReceiveSignalEvent('onReceiveSignal', [
'signal' => $signal,
'subject' => static::$instance,
])
);

switch ($signal) {
case SIGINT:
Expand Down Expand Up @@ -345,7 +355,10 @@ public function loadConfiguration($data)
public function execute()
{
// Trigger the onBeforeExecute event
$this->triggerEvent('onBeforeExecute');
$this->dispatchEvent(
'onBeforeExecute',
new BeforeExecuteEvent('onBeforeExecute', ['subject' => $this, 'container' => $this->getContainer()])
);

// Enable basic garbage collection.
gc_enable();
Expand Down Expand Up @@ -375,7 +388,10 @@ public function execute()
}

// Trigger the onAfterExecute event.
$this->triggerEvent('onAfterExecute');
$this->dispatchEvent(
'onAfterExecute',
new AfterExecuteEvent('onAfterExecute', ['subject' => $this])
);
}

/**
Expand Down Expand Up @@ -768,7 +784,10 @@ protected function writeProcessIdFile()
protected function postFork()
{
// Trigger the onFork event.
$this->triggerEvent('onFork');
$this->dispatchEvent(
'onFork',
new DeamonForkEvent('onFork', ['subject' => $this])
);
}

/**
Expand Down
14 changes: 11 additions & 3 deletions libraries/src/Application/SiteApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait;
use Joomla\CMS\Cache\Controller\OutputController;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\AfterDispatchEvent;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Event\Application\AfterRouteEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Input\Input;
Expand Down Expand Up @@ -217,7 +219,10 @@ public function dispatch($component = null)
$document->setBuffer($contents, ['type' => 'component']);

// Trigger the onAfterDispatch event.
$this->triggerEvent('onAfterDispatch');
$this->dispatchEvent(
'onAfterDispatch',
new AfterDispatchEvent('onAfterDispatch', ['subject' => $this])
);
}

/**
Expand Down Expand Up @@ -793,8 +798,11 @@ protected function route()
}

// Trigger the onAfterRoute event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterRoute');
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterRoute',
new AfterRouteEvent('onAfterRoute', ['subject' => $this])
);

$Itemid = $this->input->getInt('Itemid', null);
$this->authorise($Itemid);
Expand Down
Loading