updated core to 1.7.15

This commit is contained in:
2021-05-27 18:17:50 +02:00
parent dc1fdf21c9
commit 19ecb285ab
552 changed files with 80743 additions and 16675 deletions

View File

@@ -1,13 +1,23 @@
<?php
/**
* @package Grav.Common
* @package Grav\Common
*
* @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
namespace Grav\Common;
use Grav\Common\Form\FormFlash;
use Grav\Events\SessionStartEvent;
use Grav\Plugin\Form\Forms;
use function is_string;
/**
* Class Session
* @package Grav\Common
*/
class Session extends \Grav\Framework\Session\Session
{
/** @var bool */
@@ -15,11 +25,11 @@ class Session extends \Grav\Framework\Session\Session
/**
* @return \Grav\Framework\Session\Session
* @deprecated 1.5 Use getInstance() method instead
* @deprecated 1.5 Use ->getInstance() method instead.
*/
public static function instance()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getInstance() method instead', E_USER_DEPRECATED);
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use ->getInstance() method instead', E_USER_DEPRECATED);
return static::getInstance();
}
@@ -28,10 +38,12 @@ class Session extends \Grav\Framework\Session\Session
* Initialize session.
*
* Code in this function has been moved into SessionServiceProvider class.
*
* @return void
*/
public function init()
{
if ($this->autoStart) {
if ($this->autoStart && !$this->isStarted()) {
$this->start();
$this->autoStart = false;
@@ -53,11 +65,11 @@ class Session extends \Grav\Framework\Session\Session
* Returns attributes.
*
* @return array Attributes
* @deprecated 1.5 Use getAll() method instead
* @deprecated 1.5 Use ->getAll() method instead.
*/
public function all()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getAll() method instead', E_USER_DEPRECATED);
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use ->getAll() method instead', E_USER_DEPRECATED);
return $this->getAll();
}
@@ -65,12 +77,12 @@ class Session extends \Grav\Framework\Session\Session
/**
* Checks if the session was started.
*
* @return Boolean
* @deprecated 1.5 Use isStarted() method instead
* @return bool
* @deprecated 1.5 Use ->isStarted() method instead.
*/
public function started()
{
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use isStarted() method instead', E_USER_DEPRECATED);
user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use ->isStarted() method instead', E_USER_DEPRECATED);
return $this->isStarted();
}
@@ -84,7 +96,7 @@ class Session extends \Grav\Framework\Session\Session
*/
public function setFlashObject($name, $object)
{
$this->{$name} = serialize($object);
$this->__set($name, serialize($object));
return $this;
}
@@ -97,9 +109,34 @@ class Session extends \Grav\Framework\Session\Session
*/
public function getFlashObject($name)
{
$object = unserialize($this->{$name});
$serialized = $this->__get($name);
$this->{$name} = null;
$object = is_string($serialized) ? unserialize($serialized, ['allowed_classes' => true]) : $serialized;
$this->__unset($name);
if ($name === 'files-upload') {
$grav = Grav::instance();
// Make sure that Forms 3.0+ has been installed.
if (null === $object && isset($grav['forms'])) {
user_error(
__CLASS__ . '::' . __FUNCTION__ . '(\'files-upload\') is deprecated since Grav 1.6, use $form->getFlash()->getLegacyFiles() instead',
E_USER_DEPRECATED
);
/** @var Uri $uri */
$uri = $grav['uri'];
/** @var Forms|null $form */
$form = $grav['forms']->getActiveForm(); // @phpstan-ignore-line
$sessionField = base64_encode($uri->url);
/** @var FormFlash|null $flash */
$flash = $form ? $form->getFlash() : null; // @phpstan-ignore-line
$object = $flash && method_exists($flash, 'getLegacyFiles') ? [$sessionField => $flash->getLegacyFiles()] : null;
}
}
return $object;
}
@@ -128,11 +165,22 @@ class Session extends \Grav\Framework\Session\Session
public function getFlashCookieObject($name)
{
if (isset($_COOKIE[$name])) {
$object = json_decode($_COOKIE[$name]);
$object = json_decode($_COOKIE[$name], false);
setcookie($name, '', time() - 3600, '/');
return $object;
}
return null;
}
/**
* @return void
*/
protected function onSessionStart(): void
{
$event = new SessionStartEvent($this);
$grav = Grav::instance();
$grav->dispatchEvent($event);
}
}