mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Added new onBeforeSessionStart() Event
This commit is contained in:
parent
3f13d81c6f
commit
44c819b021
|
|
@ -4,7 +4,7 @@
|
|||
1. [](#improved)
|
||||
* Updated `bin/composer.phar` to latest `2.4.4` version [#3627](https://github.com/getgrav/grav/issues/3627)
|
||||
1. [](#bugfix)
|
||||
* Get around a bug where messages were not always being set on session during redirect
|
||||
* New `onBeforeSessionStart()` event to be used to store data lost during session regeneration (e.g. login)
|
||||
* Don't fail hard if pages recurse with same path
|
||||
* Github workflows security hardening [#3624](https://github.com/getgrav/grav/pull/3624)
|
||||
|
||||
|
|
|
|||
|
|
@ -439,12 +439,6 @@ class Grav extends Container
|
|||
{
|
||||
$response = $this->getRedirectResponse($route, $code);
|
||||
|
||||
$session = $this['session'] ?? null;
|
||||
$messages = $this['messages'] ?? null;
|
||||
if (!isset($session->messages) && $session && $messages) {
|
||||
$session->messages = $messages;
|
||||
}
|
||||
|
||||
$this->close($response);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
namespace Grav\Common;
|
||||
|
||||
use Grav\Common\Form\FormFlash;
|
||||
use Grav\Events\BeforeSessionStartEvent;
|
||||
use Grav\Events\SessionStartEvent;
|
||||
use Grav\Plugin\Form\Forms;
|
||||
use JsonException;
|
||||
|
|
@ -177,6 +178,17 @@ class Session extends \Grav\Framework\Session\Session
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function onBeforeSessionStart(): void
|
||||
{
|
||||
$event = new BeforeSessionStartEvent($this);
|
||||
|
||||
$grav = Grav::instance();
|
||||
$grav->dispatchEvent($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
|
|
|||
36
system/src/Grav/Events/BeforeSessionStartEvent.php
Normal file
36
system/src/Grav/Events/BeforeSessionStartEvent.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Events
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Events;
|
||||
|
||||
use Grav\Framework\Session\SessionInterface;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Plugins Loaded Event
|
||||
*
|
||||
* This event is called from $grav['session']->start() right before session_start() call.
|
||||
*
|
||||
* @property SessionInterface $session Session instance.
|
||||
*/
|
||||
class BeforeSessionStartEvent extends Event
|
||||
{
|
||||
/** @var SessionInterface */
|
||||
public $session;
|
||||
|
||||
public function __construct(SessionInterface $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return (array)$this;
|
||||
}
|
||||
}
|
||||
|
|
@ -317,6 +317,8 @@ class Session implements SessionInterface
|
|||
|
||||
$this->removeCookie();
|
||||
|
||||
$this->onBeforeSessionStart();
|
||||
|
||||
$success = @session_start($this->options);
|
||||
if (!$success) {
|
||||
$last = error_get_last();
|
||||
|
|
@ -456,6 +458,10 @@ class Session implements SessionInterface
|
|||
return \PHP_SAPI !== 'cli' ? \PHP_SESSION_ACTIVE === session_status() : false;
|
||||
}
|
||||
|
||||
protected function onBeforeSessionStart(): void
|
||||
{
|
||||
}
|
||||
|
||||
protected function onSessionStart(): void
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user