From 41aa5d07bad5bc4ea21f94e5b9311e9ff354b544 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Tue, 27 Feb 2018 11:43:22 +0200 Subject: [PATCH] ReplaceArrayValue, UnsetArrayValue can be restored after `var_export()` --- framework/CHANGELOG.md | 1 + framework/helpers/ReplaceArrayValue.php | 18 +++++++++++++++++- framework/helpers/UnsetArrayValue.php | 12 ++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index cb25bd4..6dface1 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -22,6 +22,7 @@ Yii Framework 2 Change Log - Enh #13702: Added support for PSR-3 'Logger' (klimov-paul) - Enh #13706: 'Profiler' layer extracted (klimov-paul) - Enh #15410: Added serialization abstraction layer under `yii\serialize\*` namespace (klimov-paul) +- Enh: Objects `yii\helpers\ReplaceArrayValue`, `yii\helpers\UnsetArrayValue` now support restoring after being exported with `var_export()` function (silverfire) - Chg: Removed methods marked as deprecated in 2.0.x (samdark) - Chg #14784: Signature of `yii\web\RequestParserInterface::parse()` changed to accept `yii\web\Request` instance as a sole argument (klimov-paul) - Chg #10771: Consistent behavior of `run()` method in all framework widgets. All return the result now for better extensibility (pkirill99, cebe) diff --git a/framework/helpers/ReplaceArrayValue.php b/framework/helpers/ReplaceArrayValue.php index 20936c5..2081ab3 100644 --- a/framework/helpers/ReplaceArrayValue.php +++ b/framework/helpers/ReplaceArrayValue.php @@ -61,7 +61,6 @@ class ReplaceArrayValue */ public $value; - /** * Constructor. * @param mixed $value value used as replacement. @@ -70,4 +69,21 @@ class ReplaceArrayValue { $this->value = $value; } + + /** + * Restores class state after using `var_export()`. + * + * @param array $state + * @return self + * @see var_export() + * @since 2.1.0 + */ + public static function __set_state($state) + { + if (!isset($state['value'])) { + throw new InvalidConfigException('Failed to instantiate class "ReplaceArrayValue". Required parameter "value" is missing'); + } + + return new self($state['value']); + } } diff --git a/framework/helpers/UnsetArrayValue.php b/framework/helpers/UnsetArrayValue.php index b0a50e2..bd1b5d6 100644 --- a/framework/helpers/UnsetArrayValue.php +++ b/framework/helpers/UnsetArrayValue.php @@ -49,4 +49,16 @@ namespace yii\helpers; */ class UnsetArrayValue { + /** + * Restores class state after using `var_export()`. + * + * @param array $state + * @return self + * @see var_export() + * @since 2.1.0 + */ + public static function __set_state($state) + { + return new self(); + } }