Skip to content

Commit

Permalink
Merge branch '1.6' into 1
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Mar 30, 2023
2 parents f8adbad + 9b32897 commit 511aef2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/Collections/DeltaConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
34 changes: 29 additions & 5 deletions src/Collections/MemoryConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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());
}

Expand All @@ -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);
}
Expand Down
22 changes: 18 additions & 4 deletions src/Middleware/MiddlewareCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? []));
}

Expand All @@ -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 ?? '')) {
Expand Down

0 comments on commit 511aef2

Please sign in to comment.