mirror of
https://github.com/getgrav/grav.git
synced 2026-03-02 10:31:41 +01:00
Added SessionStartEvent which triggers when session is started
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,9 @@ class RegisterPermissionsEvent
|
||||
{
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return (array)$this;
|
||||
}
|
||||
}
|
||||
|
||||
28
system/src/Grav/Events/SessionStartEvent.php
Normal file
28
system/src/Grav/Events/SessionStartEvent.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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\Framework\Session\Session;
|
||||
|
||||
class SessionStartEvent
|
||||
{
|
||||
/** @var Session */
|
||||
public $session;
|
||||
|
||||
public function __construct(Session $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return (array)$this;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user