From 9788a9750026af8a4c347677dc7526b4c1890c5f Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:36:18 +1200 Subject: [PATCH] API Deprecate classes which will be renamed (#11375) --- src/ORM/ArrayLib.php | 63 ++++++++++++++++++++++++++++ src/ORM/ArrayList.php | 5 +++ src/ORM/Filterable.php | 1 + src/ORM/GroupedList.php | 10 +++++ src/ORM/Limitable.php | 1 + src/ORM/ListDecorator.php | 6 +++ src/ORM/Map.php | 7 ++++ src/ORM/PaginatedList.php | 6 +++ src/ORM/SS_List.php | 2 + src/ORM/Sortable.php | 1 + src/ORM/ValidationException.php | 7 ++++ src/ORM/ValidationResult.php | 10 +++++ src/View/ArrayData.php | 7 ++++ src/View/ViewableData.php | 5 +++ src/View/ViewableData_Customised.php | 9 ++++ src/View/ViewableData_Debugger.php | 5 +++ 16 files changed, 145 insertions(+) diff --git a/src/ORM/ArrayLib.php b/src/ORM/ArrayLib.php index 371d0f6dfca..d3c4815e6f1 100644 --- a/src/ORM/ArrayLib.php +++ b/src/ORM/ArrayLib.php @@ -3,12 +3,20 @@ namespace SilverStripe\ORM; use Generator; +use SilverStripe\Dev\Deprecation; /** * Library of static methods for manipulating arrays. + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib */ class ArrayLib { + public function __construct() + { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib', Deprecation::SCOPE_CLASS); + }); + } /** * Inverses the first and second level keys of an associative @@ -45,9 +53,14 @@ class ArrayLib * * @param array $arr * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::invert() */ public static function invert($arr) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invert()'); + }); + if (!$arr) { return []; } @@ -68,9 +81,14 @@ public static function invert($arr) * * @param $arr array * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::valuekey() */ public static function valuekey($arr) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::valuekey()'); + }); + return array_combine($arr ?? [], $arr ?? []); } @@ -79,9 +97,14 @@ public static function valuekey($arr) * * @param array $array * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_values_recursive() */ public static function array_values_recursive($array) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invearray_values_recursivert()'); + }); + return ArrayLib::flatten($array, false); } @@ -93,9 +116,14 @@ public static function array_values_recursive($array) * @param $keys array * * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::filter_keys() */ public static function filter_keys($arr, $keys) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::filter_keys()'); + }); + foreach ($arr as $key => $v) { if (!in_array($key, $keys ?? [])) { unset($arr[$key]); @@ -114,9 +142,14 @@ public static function filter_keys($arr, $keys) * @param array $array * * @return boolean + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::is_associative() */ public static function is_associative($array) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::is_associative()'); + }); + $isAssociative = !empty($array) && is_array($array) && ($array !== array_values($array ?? [])); @@ -135,9 +168,14 @@ public static function is_associative($array) * @param boolean $strict * * @return boolean + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive() */ public static function in_array_recursive($needle, $haystack, $strict = false) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive()'); + }); + if (!is_array($haystack)) { return false; } @@ -163,9 +201,14 @@ public static function in_array_recursive($needle, $haystack, $strict = false) * @param $f callback to apply * @param $array array * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_map_recursive() */ public static function array_map_recursive($f, $array) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_map_recursive()'); + }); + $applyOrRecurse = function ($v) use ($f) { return is_array($v) ? ArrayLib::array_map_recursive($f, $v) : call_user_func($f, $v); }; @@ -184,9 +227,14 @@ public static function array_map_recursive($f, $array) * @param array $array * * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive() */ public static function array_merge_recursive($array) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive()'); + }); + $arrays = func_get_args(); $merged = []; @@ -229,9 +277,14 @@ public static function array_merge_recursive($array) * @param array $out * * @return array + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::flatten() */ public static function flatten($array, $preserveKeys = true, &$out = []) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::flatten()'); + }); + array_walk_recursive( $array, function ($value, $key) use (&$out, $preserveKeys) { @@ -256,9 +309,14 @@ function ($value, $key) use (&$out, $preserveKeys) { * * @param array $list * @return Generator + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile() */ public static function iterateVolatile(array &$list) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile()'); + }); + // Keyed by already-iterated items $iterated = []; // Get all items not yet iterated @@ -278,9 +336,14 @@ public static function iterateVolatile(array &$list) /** * Similar to shuffle, but retains the existing association between the keys and the values. * Shuffles the array in place. + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::shuffleAssociative() */ public static function shuffleAssociative(array &$array): void { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::shuffleAssociative()'); + }); + $shuffledArray = []; $keys = array_keys($array); shuffle($keys); diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index 16fc11de402..94920fe3e99 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -35,6 +35,7 @@ * @implements Filterable * @implements Sortable * @implements Limitable + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\ArrayList */ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, Limitable { @@ -60,6 +61,10 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function __construct(array $items = []) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\ArrayList', Deprecation::SCOPE_CLASS); + }); + $this->items = array_values($items ?? []); parent::__construct(); } diff --git a/src/ORM/Filterable.php b/src/ORM/Filterable.php index ce5196e4654..4caf7032fc7 100644 --- a/src/ORM/Filterable.php +++ b/src/ORM/Filterable.php @@ -14,6 +14,7 @@ * * @template T * @extends SS_List + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Filterable */ interface Filterable extends SS_List { diff --git a/src/ORM/GroupedList.php b/src/ORM/GroupedList.php index 6fdd257d80d..e81d5bbbede 100644 --- a/src/ORM/GroupedList.php +++ b/src/ORM/GroupedList.php @@ -2,6 +2,7 @@ namespace SilverStripe\ORM; +use SilverStripe\Dev\Deprecation; use SilverStripe\View\ArrayData; /** @@ -11,10 +12,19 @@ * @template TList * @template T * @extends ListDecorator + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\GroupedList */ class GroupedList extends ListDecorator { + public function __construct(SS_List&Sortable&Filterable&Limitable $list) + { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\GroupedList', Deprecation::SCOPE_CLASS); + }); + parent::__construct($list); + } + /** * @param string $index * @return array diff --git a/src/ORM/Limitable.php b/src/ORM/Limitable.php index 4a2d37b3ad0..f9e29064943 100644 --- a/src/ORM/Limitable.php +++ b/src/ORM/Limitable.php @@ -14,6 +14,7 @@ * * @template T * @implements SS_List + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Limitable */ interface Limitable extends SS_List { diff --git a/src/ORM/ListDecorator.php b/src/ORM/ListDecorator.php index b063acb7481..94712368afe 100644 --- a/src/ORM/ListDecorator.php +++ b/src/ORM/ListDecorator.php @@ -4,6 +4,7 @@ use SilverStripe\View\ViewableData; use LogicException; +use SilverStripe\Dev\Deprecation; use Traversable; /** @@ -17,6 +18,7 @@ * @implements Sortable * @implements Filterable * @implements Limitable + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\ListDecorator */ abstract class ListDecorator extends ViewableData implements SS_List, Sortable, Filterable, Limitable { @@ -30,6 +32,10 @@ abstract class ListDecorator extends ViewableData implements SS_List, Sortable, */ public function __construct(SS_List&Sortable&Filterable&Limitable $list) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\ListDecorator', Deprecation::SCOPE_CLASS); + }); + $this->setList($list); parent::__construct(); diff --git a/src/ORM/Map.php b/src/ORM/Map.php index a1b81f609d8..186cf2246fd 100644 --- a/src/ORM/Map.php +++ b/src/ORM/Map.php @@ -6,10 +6,13 @@ use BadMethodCallException; use Countable; use IteratorAggregate; +use SilverStripe\Dev\Deprecation; use Traversable; /** * Creates a map from an SS_List by defining a key column and a value column. + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Map */ class Map implements ArrayAccess, Countable, IteratorAggregate { @@ -39,6 +42,10 @@ class Map implements ArrayAccess, Countable, IteratorAggregate */ public function __construct(SS_List $list, $keyField = "ID", $valueField = "Title") { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\Map', Deprecation::SCOPE_CLASS); + }); + $this->list = $list; $this->keyField = $keyField; $this->valueField = $valueField; diff --git a/src/ORM/PaginatedList.php b/src/ORM/PaginatedList.php index 99e7ebb818a..b7d392700f4 100644 --- a/src/ORM/PaginatedList.php +++ b/src/ORM/PaginatedList.php @@ -9,6 +9,7 @@ use ArrayAccess; use Exception; use IteratorIterator; +use SilverStripe\Dev\Deprecation; use Traversable; /** @@ -17,6 +18,7 @@ * @template TList of SS_List * @template T * @extends ListDecorator + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\PaginatedList */ class PaginatedList extends ListDecorator { @@ -39,6 +41,10 @@ class PaginatedList extends ListDecorator */ public function __construct(SS_List $list, $request = []) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\PaginatedList', Deprecation::SCOPE_CLASS); + }); + if (!is_array($request) && !$request instanceof ArrayAccess) { throw new Exception('The request must be readable as an array.'); } diff --git a/src/ORM/SS_List.php b/src/ORM/SS_List.php index 2aa82783d3f..4cb769a86ba 100644 --- a/src/ORM/SS_List.php +++ b/src/ORM/SS_List.php @@ -12,6 +12,8 @@ * @template T * @extends ArrayAccess * @extends IteratorAggregate + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\SS_List */ interface SS_List extends ArrayAccess, Countable, IteratorAggregate { diff --git a/src/ORM/Sortable.php b/src/ORM/Sortable.php index 07c9e92fc5a..2fd84c9111c 100644 --- a/src/ORM/Sortable.php +++ b/src/ORM/Sortable.php @@ -14,6 +14,7 @@ * * @template T * @implements SS_List + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Sortable */ interface Sortable extends SS_List { diff --git a/src/ORM/ValidationException.php b/src/ORM/ValidationException.php index 88f9192094b..1ee47db2793 100644 --- a/src/ORM/ValidationException.php +++ b/src/ORM/ValidationException.php @@ -5,11 +5,14 @@ use Exception; use InvalidArgumentException; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\Dev\Deprecation; /** * Exception thrown by {@link DataObject}::write if validation fails. By throwing an * exception rather than a user error, the exception can be caught in unit tests and as such * can be used as a successful test. + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\Validation\ValidationException */ class ValidationException extends Exception { @@ -31,6 +34,10 @@ class ValidationException extends Exception */ public function __construct($result = null, $code = 0) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\Validation\ValidationException', Deprecation::SCOPE_CLASS); + }); + // Catch legacy behaviour where second argument was not code if ($code && !is_numeric($code)) { throw new InvalidArgumentException("Code must be numeric"); diff --git a/src/ORM/ValidationResult.php b/src/ORM/ValidationResult.php index 8ba3ba545ba..d57a3b8b24d 100644 --- a/src/ORM/ValidationResult.php +++ b/src/ORM/ValidationResult.php @@ -4,6 +4,7 @@ use InvalidArgumentException; use SilverStripe\Core\Injector\Injectable; +use SilverStripe\Dev\Deprecation; /** * A class that combined as a boolean result with an optional list of error messages. @@ -11,6 +12,8 @@ * * Each message can have a code or field which will uniquely identify that message. However, * messages can be stored without a field or message as an "overall" message. + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Core\Validation\ValidationResult */ class ValidationResult { @@ -61,6 +64,13 @@ class ValidationResult */ protected $messages = []; + public function __construct() + { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\Validation\ValidationResult', Deprecation::SCOPE_CLASS); + }); + } + /** * Record an error against this validation result, * diff --git a/src/View/ArrayData.php b/src/View/ArrayData.php index 1d166de5305..34786a962b1 100644 --- a/src/View/ArrayData.php +++ b/src/View/ArrayData.php @@ -4,6 +4,7 @@ use SilverStripe\ORM\ArrayLib; use InvalidArgumentException; +use SilverStripe\Dev\Deprecation; use stdClass; /** @@ -15,6 +16,8 @@ * "AddAction" => "Add a new Page page", * )); * + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\ArrayData */ class ArrayData extends ViewableData { @@ -31,6 +34,10 @@ class ArrayData extends ViewableData */ public function __construct($value = []) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\ArrayData', Deprecation::SCOPE_CLASS); + }); + if (is_object($value)) { $this->array = get_object_vars($value); } elseif (is_array($value)) { diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index d729d36da72..37970ba691d 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -32,6 +32,8 @@ * A view interrogates the object being currently rendered in order to get data to render into the template. This data * is provided and automatically escaped by ViewableData. Any class that needs to be available to a view (controllers, * {@link DataObject}s, page controls) should inherit from this class. + * + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\ModelData */ class ViewableData implements IteratorAggregate { @@ -97,6 +99,9 @@ class ViewableData implements IteratorAggregate public function __construct() { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\ModelData', Deprecation::SCOPE_CLASS); + }); } // ----------------------------------------------------------------------------------------------------------------- diff --git a/src/View/ViewableData_Customised.php b/src/View/ViewableData_Customised.php index a8589bb51a8..0988b2957f7 100644 --- a/src/View/ViewableData_Customised.php +++ b/src/View/ViewableData_Customised.php @@ -2,6 +2,11 @@ namespace SilverStripe\View; +use SilverStripe\Dev\Deprecation; + +/** + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\ModelDataCustomised + */ class ViewableData_Customised extends ViewableData { @@ -18,6 +23,10 @@ class ViewableData_Customised extends ViewableData */ public function __construct(ViewableData $originalObject, ViewableData $customisedObject) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\ModelDataCustomised', Deprecation::SCOPE_CLASS); + }); + $this->original = $originalObject; $this->customised = $customisedObject; diff --git a/src/View/ViewableData_Debugger.php b/src/View/ViewableData_Debugger.php index 9c496c99a4f..c2ea7357b6c 100644 --- a/src/View/ViewableData_Debugger.php +++ b/src/View/ViewableData_Debugger.php @@ -3,9 +3,11 @@ namespace SilverStripe\View; use ReflectionObject; +use SilverStripe\Dev\Deprecation; /** * Allows you to render debug information about a {@link ViewableData} object into a template. + * @deprecated 5.4.0 Will be renamed to SilverStripe\Model\ModelDataDebugger */ class ViewableData_Debugger extends ViewableData { @@ -20,6 +22,9 @@ class ViewableData_Debugger extends ViewableData */ public function __construct(ViewableData $object) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\ModelDataDebugger', Deprecation::SCOPE_CLASS); + }); $this->object = $object; parent::__construct(); }