From 5adadfdb404550cdf0a694c02ebe2db55e9a6cfd Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 16 Jan 2020 14:44:52 +0200 Subject: [PATCH] Added `SessionStartEvent` which triggers when session is started --- CHANGELOG.md | 2 ++ system/src/Grav/Common/Session.php | 9 ++++++ .../Grav/Events/RegisterPermissionsEvent.php | 5 ++++ system/src/Grav/Events/SessionStartEvent.php | 28 +++++++++++++++++++ system/src/Grav/Framework/Session/Session.php | 5 ++++ 5 files changed, 49 insertions(+) create mode 100644 system/src/Grav/Events/SessionStartEvent.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1811a700d..33336e1be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 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 `SessionStartEvent` which triggers when session is started 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) diff --git a/system/src/Grav/Common/Session.php b/system/src/Grav/Common/Session.php index f8018e6c9..0a4e0450d 100644 --- a/system/src/Grav/Common/Session.php +++ b/system/src/Grav/Common/Session.php @@ -10,6 +10,7 @@ namespace Grav\Common; use Grav\Common\Form\FormFlash; +use Grav\Events\SessionStartEvent; class Session extends \Grav\Framework\Session\Session { @@ -163,4 +164,12 @@ class Session extends \Grav\Framework\Session\Session return null; } + + protected function onSessionStart(): void + { + $event = new SessionStartEvent($this); + + $grav = Grav::instance(); + $grav->dispatchEvent($event); + } } diff --git a/system/src/Grav/Events/RegisterPermissionsEvent.php b/system/src/Grav/Events/RegisterPermissionsEvent.php index 3556a0bee..ab86ac497 100644 --- a/system/src/Grav/Events/RegisterPermissionsEvent.php +++ b/system/src/Grav/Events/RegisterPermissionsEvent.php @@ -20,4 +20,9 @@ class RegisterPermissionsEvent { $this->permissions = $permissions; } + + public function __debugInfo(): array + { + return (array)$this; + } } diff --git a/system/src/Grav/Events/SessionStartEvent.php b/system/src/Grav/Events/SessionStartEvent.php new file mode 100644 index 000000000..0f163d04e --- /dev/null +++ b/system/src/Grav/Events/SessionStartEvent.php @@ -0,0 +1,28 @@ +session = $session; + } + + public function __debugInfo(): array + { + return (array)$this; + } +} diff --git a/system/src/Grav/Framework/Session/Session.php b/system/src/Grav/Framework/Session/Session.php index c8fa45ab3..26e0c6847 100644 --- a/system/src/Grav/Framework/Session/Session.php +++ b/system/src/Grav/Framework/Session/Session.php @@ -203,6 +203,7 @@ class Session implements SessionInterface } $this->started = true; + $this->onSessionStart(); $user = $this->__get('user'); if ($user && (!$user instanceof UserInterface || !$user->isValid())) { @@ -345,6 +346,10 @@ class Session implements SessionInterface return \PHP_SAPI !== 'cli' ? \PHP_SESSION_ACTIVE === session_status() : false; } + protected function onSessionStart(): void + { + } + /** * @param string $key * @param mixed $value