mirror of
https://github.com/getgrav/grav.git
synced 2026-07-08 13:42:04 +02:00
Fixed unserialize in MarkdownFormatter class
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
1. [](#bugfix)
|
||||
* Fixed port issue with `system.custom_base_url`
|
||||
* Hide errors with `exif_read_data` in `ImageFile`
|
||||
* Fixed unserialize in `MarkdownFormatter` class
|
||||
|
||||
# v1.7.0-rc.20
|
||||
## 12/15/2020
|
||||
|
||||
39
system/src/Grav/Framework/Compat/Serializable.php
Normal file
39
system/src/Grav/Framework/Compat/Serializable.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Framework\Compat
|
||||
*
|
||||
* @copyright Copyright (C) 2015 - 2020 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Framework\Compat;
|
||||
|
||||
/**
|
||||
* Serializable trait
|
||||
*
|
||||
* Adds backwards compatibility to PHP 7.3 Serializable interface.
|
||||
*
|
||||
* Note: Remember to add: `implements \Serializable` to the classes which use this trait.
|
||||
*
|
||||
* @package Grav\Framework\Traits
|
||||
*/
|
||||
trait Serializable
|
||||
{
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function serialize(): ?string
|
||||
{
|
||||
return serialize($this->__serialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serialized
|
||||
* @return void
|
||||
*/
|
||||
public function unserialize($serialized): void
|
||||
{
|
||||
$this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Grav\Framework\File\Formatter;
|
||||
|
||||
use Grav\Framework\Compat\Serializable;
|
||||
use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,8 @@ use Grav\Framework\File\Interfaces\FileFormatterInterface;
|
||||
*/
|
||||
abstract class AbstractFormatter implements FileFormatterInterface
|
||||
{
|
||||
use Serializable;
|
||||
|
||||
/** @var array */
|
||||
private $config;
|
||||
|
||||
@@ -32,23 +35,6 @@ abstract class AbstractFormatter implements FileFormatterInterface
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(): string
|
||||
{
|
||||
return serialize($this->doSerialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $serialized
|
||||
* @return void
|
||||
*/
|
||||
public function unserialize($serialized): void
|
||||
{
|
||||
$this->doUnserialize(unserialize($serialized, ['allowed_classes' => false]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -95,6 +81,24 @@ abstract class AbstractFormatter implements FileFormatterInterface
|
||||
*/
|
||||
abstract public function decode($data);
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return ['config' => $this->config];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
$this->config = $data['config'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get either full configuration or a single option.
|
||||
*
|
||||
@@ -109,23 +113,4 @@ abstract class AbstractFormatter implements FileFormatterInterface
|
||||
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function doSerialize(): array
|
||||
{
|
||||
return ['config' => $this->config];
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: if overridden, make sure you call parent::doUnserialize()
|
||||
*
|
||||
* @param array $serialized
|
||||
* @return void
|
||||
*/
|
||||
protected function doUnserialize(array $serialized): void
|
||||
{
|
||||
$this->config = $serialized['config'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class MarkdownFormatter extends AbstractFormatter
|
||||
|
||||
parent::__construct($config);
|
||||
|
||||
$this->headerFormatter = $headerFormatter ?: new YamlFormatter($config['yaml']);
|
||||
$this->headerFormatter = $headerFormatter ?? new YamlFormatter($config['yaml']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,4 +145,16 @@ class MarkdownFormatter extends AbstractFormatter
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
return parent::__serialize() + ['headerFormatter' => $this->headerFormatter];
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
parent::__unserialize($data);
|
||||
|
||||
$this->headerFormatter = $data['headerFormatter'] ?? new YamlFormatter(['inline' => 20]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user