mirror of
https://github.com/getgrav/grav.git
synced 2026-03-02 10:31:41 +01:00
Added PluginsLoadedEvent which triggers after plugins have been loaded but not yet initialized
This commit is contained in:
@@ -3,8 +3,9 @@
|
||||
|
||||
1. [](#new)
|
||||
* _POTENTIAL BREAKING CHANGE:_ Upgraded Parsedown to 1.7 for Parsedown-Extra 0.8. Plugins that extend Parsedown may need a fix to render as HTML
|
||||
* Added `RegisterPermissionsEvent` which triggers when `$grav['permissions']` is being accessed the first time
|
||||
* Added `PluginsLoadedEvent` which triggers after plugins have been loaded but not yet initialized
|
||||
* Added `SessionStartEvent` which triggers when session is started
|
||||
* Added `RegisterPermissionsEvent` which triggers when `$grav['permissions']` is being accessed the first time
|
||||
1. [](#improved)
|
||||
* Blueprint validation: Added `validate: value_type: bool|int|float|string|trim` to `array` to filter all the values inside the array
|
||||
1. [](#bugfix)
|
||||
|
||||
@@ -12,8 +12,10 @@ namespace Grav\Common\Processors;
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Debugger;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Plugins;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Events\PluginsLoadedEvent;
|
||||
use Grav\Framework\Psr7\Response;
|
||||
use Grav\Framework\Session\Exceptions\SessionException;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
@@ -61,11 +63,14 @@ class InitializeProcessor extends ProcessorBase
|
||||
$this->stopTimer('_debugger');
|
||||
|
||||
$this->initialize($config);
|
||||
|
||||
$this->loadPlugins();
|
||||
|
||||
$this->initializeSession($config);
|
||||
|
||||
// Wrap call to next handler so that debugger can profile it.
|
||||
/** @var Response $response */
|
||||
$response = $debugger->profile(function () use ($handler, $request) {
|
||||
$response = $debugger->profile(static function () use ($handler, $request) {
|
||||
return $handler->handle($request);
|
||||
});
|
||||
|
||||
@@ -89,6 +94,9 @@ class InitializeProcessor extends ProcessorBase
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*/
|
||||
protected function initializeLogger(Config $config): void
|
||||
{
|
||||
$this->startTimer('_logger', 'Logger');
|
||||
@@ -123,10 +131,15 @@ class InitializeProcessor extends ProcessorBase
|
||||
$this->stopTimer('_errors');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*/
|
||||
protected function initialize(Config $config): void
|
||||
{
|
||||
$this->startTimer('_init', 'Initialize');
|
||||
|
||||
$grav = $this->container;
|
||||
|
||||
// Use output buffering to prevent headers from being sent too early.
|
||||
ob_start();
|
||||
if ($config->get('system.cache.gzip') && !@ob_start('ob_gzhandler')) {
|
||||
@@ -141,11 +154,11 @@ class InitializeProcessor extends ProcessorBase
|
||||
}
|
||||
|
||||
/** @var Pages $pages */
|
||||
$pages = $this->container['pages'];
|
||||
$pages = $grav['pages'];
|
||||
$pages->register();
|
||||
|
||||
/** @var Uri $uri */
|
||||
$uri = $this->container['uri'];
|
||||
$uri = $grav['uri'];
|
||||
$uri->init();
|
||||
|
||||
// Redirect pages with trailing slash if configured to do so.
|
||||
@@ -154,14 +167,34 @@ class InitializeProcessor extends ProcessorBase
|
||||
&& $config->get('system.pages.redirect_trailing_slash', false)
|
||||
&& Utils::endsWith($path, '/')) {
|
||||
$redirect = (string) $uri::getCurrentRoute()->toString();
|
||||
$this->container->redirect($redirect);
|
||||
$grav->redirect($redirect);
|
||||
}
|
||||
|
||||
$this->container->setLocale();
|
||||
$grav->setLocale();
|
||||
|
||||
$this->stopTimer('_init');
|
||||
}
|
||||
|
||||
protected function loadPlugins(): void
|
||||
{
|
||||
$this->startTimer('_plugins_load', 'Load Plugins');
|
||||
|
||||
$grav = $this->container;
|
||||
|
||||
/** @var Plugins $plugins */
|
||||
$plugins = $grav['plugins'];
|
||||
$plugins->init();
|
||||
|
||||
// Plugins Loaded Event
|
||||
$event = new PluginsLoadedEvent($grav, $plugins);
|
||||
$grav->dispatchEvent($event);
|
||||
|
||||
$this->stopTimer('_plugins_load');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
*/
|
||||
protected function initializeSession(Config $config): void
|
||||
{
|
||||
// FIXME: Initialize session should happen later after plugins have been loaded. This is a workaround to fix session issues in AWS.
|
||||
|
||||
@@ -18,15 +18,16 @@ class PluginsProcessor extends ProcessorBase
|
||||
/** @var string */
|
||||
public $id = 'plugins';
|
||||
/** @var string */
|
||||
public $title = 'Plugins';
|
||||
public $title = 'Initialize Plugins';
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$this->startTimer();
|
||||
$this->container['accounts'];
|
||||
$this->container['pages'];
|
||||
$this->container['plugins']->init();
|
||||
$this->container->fireEvent('onPluginsInitialized');
|
||||
$grav = $this->container;
|
||||
|
||||
$grav['accounts'];
|
||||
|
||||
$grav->fireEvent('onPluginsInitialized');
|
||||
$this->stopTimer();
|
||||
|
||||
return $handler->handle($request);
|
||||
|
||||
34
system/src/Grav/Events/PluginsLoadedEvent.php
Normal file
34
system/src/Grav/Events/PluginsLoadedEvent.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Events
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Events;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Plugins;
|
||||
|
||||
class PluginsLoadedEvent
|
||||
{
|
||||
/** @var Grav */
|
||||
public $grav;
|
||||
/** @var Plugins */
|
||||
public $plugins;
|
||||
|
||||
public function __construct(Grav $grav, Plugins $plugins)
|
||||
{
|
||||
$this->grav = $grav;
|
||||
$this->plugins = $plugins;
|
||||
}
|
||||
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return [
|
||||
'plugins' => $this->plugins
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user