From e4a66ae63348bbd95f4c30b70789ad8380409e82 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 17 Mar 2023 18:53:56 +1300 Subject: [PATCH] DEP Decouple from silverstripe/framework --- composer.json | 5 ++-- src/Collections/DeltaConfigCollection.php | 6 +++- src/Collections/MemoryConfigCollection.php | 34 ++++++++++++++++++---- src/Middleware/MiddlewareCommon.php | 22 +++++++++++--- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index a80309f..5fa0c7b 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,7 @@ "symfony/finder": "^3.4 || ^4.0", "symfony/yaml": "^3.4 || ^4.0", "marcj/topsort": "^1 || ^2", - "psr/simple-cache": "^1.0", - "silverstripe/framework": "^4.12" + "psr/simple-cache": "^1.0" }, "require-dev": { "phpunit/phpunit": "^9.5", @@ -21,4 +20,4 @@ "SilverStripe\\Config\\Tests\\": "tests/" } } -} \ No newline at end of file +} diff --git a/src/Collections/DeltaConfigCollection.php b/src/Collections/DeltaConfigCollection.php index 7f5e870..b464519 100644 --- a/src/Collections/DeltaConfigCollection.php +++ b/src/Collections/DeltaConfigCollection.php @@ -151,7 +151,11 @@ public function isDeltaReset($class = null) */ public function unserialize($serialized) { - Deprecation::notice('1.6.0', 'Use __unserialize() instead'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.6.0', 'Use __unserialize() instead'); + } else { + user_error(__METHOD__ . ' is deprecated. Use __unserialize() instead', E_USER_DEPRECATED); + } parent::unserialize($serialized); $this->postInit(); } diff --git a/src/Collections/MemoryConfigCollection.php b/src/Collections/MemoryConfigCollection.php index 6ffe745..1239b93 100644 --- a/src/Collections/MemoryConfigCollection.php +++ b/src/Collections/MemoryConfigCollection.php @@ -118,7 +118,11 @@ public function checkForDeprecatedConfig($class, $name): void $deprecated = $this->getClassConfig('__deprecated', true); $data = $deprecated['config'][strtolower($class)][$name] ?? []; if (!empty($data)) { - Deprecation::notice($data['version'], $data['message'], Deprecation::SCOPE_CONFIG); + if (class_exists(Deprecation::class)) { + Deprecation::notice($data['version'], $data['message'], Deprecation::SCOPE_CONFIG); + } else { + user_error($data['message'], E_USER_DEPRECATED); + } } } @@ -216,7 +220,11 @@ public function getAll() */ public function update($class, $name, $value) { - Deprecation::notice('1.0.0', 'Use merge() instead'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.0.0', 'Use merge() instead'); + } else { + user_error(__METHOD__ . ' is deprecated. Use merge() instead', E_USER_DEPRECATED); + } $this->merge($class, $name, $value); return $this; } @@ -229,7 +237,15 @@ public function update($class, $name, $value) public function merge($class, $name, $value) { if (!is_array($value)) { - Deprecation::notice('1.12.0', 'Use set() if $value is not an array instead'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.12.0', 'Use set() if $value is not an array instead'); + } else { + user_error( + 'Non-array values for the $value argument in ' . __METHOD__ + . ' are deprecated. Use set() if $value is not an array instead', + E_USER_DEPRECATED + ); + } } // Detect mergeable config $existing = $this->get($class, $name, true); @@ -297,7 +313,11 @@ public function __unserialize(array $data): void */ public function serialize() { - Deprecation::notice('1.12.0', 'Use __serialize() instead'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.12.0', 'Use __serialize() instead'); + } else { + user_error(__METHOD__ . ' is deprecated. Use __serialize() instead', E_USER_DEPRECATED); + } return serialize($this->__serialize()); } @@ -311,7 +331,11 @@ public function serialize() */ public function unserialize($serialized) { - Deprecation::notice('1.12.0', 'Use __unserialize() instead'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.12.0', 'Use __unserialize() instead'); + } else { + user_error(__METHOD__ . ' is deprecated. Use __unserialize() instead', E_USER_DEPRECATED); + } $data = unserialize($serialized ?? ''); $this->__unserialize($data); } diff --git a/src/Middleware/MiddlewareCommon.php b/src/Middleware/MiddlewareCommon.php index bbfd279..4201322 100644 --- a/src/Middleware/MiddlewareCommon.php +++ b/src/Middleware/MiddlewareCommon.php @@ -71,11 +71,18 @@ public function __unserialize(array $data): void * The __serialize() magic method will be automatically used instead of this * * @return string - * @deprecated 1.12.0 Will be removed without equivalent functionality to replace it + * @deprecated 1.12.0 Will be replaced with __serialize() */ public function serialize() { - Deprecation::notice('1.12.0', 'Will be removed without equivalent functionality to replace it'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.12.0', 'Will be replaced with __serialize()'); + } else { + user_error( + __METHOD__ . ' is deprecated. Will be replaced with __serialize()', + E_USER_DEPRECATED + ); + } return json_encode(array_values($this->__serialize() ?? [])); } @@ -85,11 +92,18 @@ public function serialize() * and the PHP version used in less than PHP 9.0 * * @param string $serialized - * @deprecated 1.12.0 Will be removed without equivalent functionality to replace it + * @deprecated 1.12.0 Will be replaced with __unserialize() */ public function unserialize($serialized) { - Deprecation::notice('1.12.0', 'Will be removed without equivalent functionality to replace it'); + if (class_exists(Deprecation::class)) { + Deprecation::notice('1.12.0', 'Will be replaced with __unserialize()'); + } else { + user_error( + __METHOD__ . ' is deprecated. Will be replaced with __unserialize()', + E_USER_DEPRECATED + ); + } $values = json_decode($serialized ?? '', true); foreach (array_keys($this->__serialize() ?? []) as $i => $key) { if (!property_exists($this, $key ?? '')) {