Skip to content

Commit

Permalink
API Deprecate classes which will be renamed (#11375)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Sep 12, 2024
1 parent b926834 commit 9788a97
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/ORM/ArrayLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [];
}
Expand All @@ -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 ?? []);
}

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

Expand All @@ -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]);
Expand All @@ -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 ?? []));
Expand All @@ -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;
}
Expand All @@ -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);
};
Expand All @@ -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 = [];

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/ORM/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @implements Filterable<T>
* @implements Sortable<T>
* @implements Limitable<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\ArrayList
*/
class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, Limitable
{
Expand All @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions src/ORM/Filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @template T
* @extends SS_List<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Filterable
*/
interface Filterable extends SS_List
{
Expand Down
10 changes: 10 additions & 0 deletions src/ORM/GroupedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\ORM;

use SilverStripe\Dev\Deprecation;
use SilverStripe\View\ArrayData;

/**
Expand All @@ -11,10 +12,19 @@
* @template TList
* @template T
* @extends ListDecorator<TList, T>
* @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
Expand Down
1 change: 1 addition & 0 deletions src/ORM/Limitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @template T
* @implements SS_List<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Limitable
*/
interface Limitable extends SS_List
{
Expand Down
6 changes: 6 additions & 0 deletions src/ORM/ListDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\View\ViewableData;
use LogicException;
use SilverStripe\Dev\Deprecation;
use Traversable;

/**
Expand All @@ -17,6 +18,7 @@
* @implements Sortable<T>
* @implements Filterable<T>
* @implements Limitable<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\ListDecorator
*/
abstract class ListDecorator extends ViewableData implements SS_List, Sortable, Filterable, Limitable
{
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/ORM/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/ORM/PaginatedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ArrayAccess;
use Exception;
use IteratorIterator;
use SilverStripe\Dev\Deprecation;
use Traversable;

/**
Expand All @@ -17,6 +18,7 @@
* @template TList of SS_List
* @template T
* @extends ListDecorator<TList, T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\PaginatedList
*/
class PaginatedList extends ListDecorator
{
Expand All @@ -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.');
}
Expand Down
2 changes: 2 additions & 0 deletions src/ORM/SS_List.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @template T
* @extends ArrayAccess<array-key, T>
* @extends IteratorAggregate<array-key, T>
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\SS_List
*/
interface SS_List extends ArrayAccess, Countable, IteratorAggregate
{
Expand Down
1 change: 1 addition & 0 deletions src/ORM/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @template T
* @implements SS_List<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Sortable
*/
interface Sortable extends SS_List
{
Expand Down
7 changes: 7 additions & 0 deletions src/ORM/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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");
Expand Down
Loading

0 comments on commit 9788a97

Please sign in to comment.