Added SessionStartEvent which triggers when session is started

This commit is contained in:
Matias Griese
2020-01-16 14:44:52 +02:00
parent 7574195ca2
commit 5adadfdb40
5 changed files with 49 additions and 0 deletions

View File

@@ -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)

View File

@@ -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);
}
}

View File

@@ -20,4 +20,9 @@ class RegisterPermissionsEvent
{
$this->permissions = $permissions;
}
public function __debugInfo(): array
{
return (array)$this;
}
}

View 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;
}
}

View File

@@ -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