Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP Decouple from silverstripe/framework #82

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 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 All @@ -21,4 +20,4 @@
"SilverStripe\\Config\\Tests\\": "tests/"
}
}
}
}
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