Merge branch '5' into 6

This commit is contained in:
github-actions 2024-09-12 05:44:26 +00:00
commit 755d5acb40
16 changed files with 145 additions and 0 deletions

View File

@ -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 @@ class ArrayLib
*
* @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 @@ class ArrayLib
*
* @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 @@ class ArrayLib
* @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 @@ class ArrayLib
* @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 @@ class ArrayLib
* @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 @@ class ArrayLib
* @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 @@ class ArrayLib
* @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 @@ class ArrayLib
* @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 @@ class ArrayLib
*
* @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 @@ class ArrayLib
/**
* 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);

View File

@ -35,6 +35,7 @@ use Traversable;
* @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
{
@ -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();
}

View File

@ -14,6 +14,7 @@ namespace SilverStripe\ORM;
*
* @template T
* @extends SS_List<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Filterable
*/
interface Filterable extends SS_List
{

View File

@ -2,6 +2,7 @@
namespace SilverStripe\ORM;
use SilverStripe\Dev\Deprecation;
use SilverStripe\View\ArrayData;
/**
@ -11,10 +12,19 @@ use SilverStripe\View\ArrayData;
* @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

View File

@ -14,6 +14,7 @@ namespace SilverStripe\ORM;
*
* @template T
* @implements SS_List<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Limitable
*/
interface Limitable extends SS_List
{

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ORM;
use SilverStripe\View\ViewableData;
use LogicException;
use SilverStripe\Dev\Deprecation;
use Traversable;
/**
@ -17,6 +18,7 @@ use Traversable;
* @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
{
@ -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();

View File

@ -6,10 +6,13 @@ use ArrayAccess;
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;

View File

@ -9,6 +9,7 @@ use SilverStripe\View\ArrayData;
use ArrayAccess;
use Exception;
use IteratorIterator;
use SilverStripe\Dev\Deprecation;
use Traversable;
/**
@ -17,6 +18,7 @@ use Traversable;
* @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
{
@ -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.');
}

View File

@ -12,6 +12,8 @@ use IteratorAggregate;
* @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
{

View File

@ -14,6 +14,7 @@ namespace SilverStripe\ORM;
*
* @template T
* @implements SS_List<T>
* @deprecated 5.4.0 Will be renamed to SilverStripe\Model\List\Sortable
*/
interface Sortable extends SS_List
{

View File

@ -5,11 +5,14 @@ namespace SilverStripe\ORM;
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");

View File

@ -4,6 +4,7 @@ namespace SilverStripe\ORM;
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 @@ use SilverStripe\Core\Injector\Injectable;
*
* 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,
*

View File

@ -4,6 +4,7 @@ namespace SilverStripe\View;
use SilverStripe\ORM\ArrayLib;
use InvalidArgumentException;
use SilverStripe\Dev\Deprecation;
use stdClass;
/**
@ -15,6 +16,8 @@ use stdClass;
* "AddAction" => "Add a new Page page",
* ));
* </code>
*
* @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)) {

View File

@ -27,6 +27,8 @@ use UnexpectedValueException;
* 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
{
@ -75,6 +77,9 @@ class ViewableData
public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\ModelData', Deprecation::SCOPE_CLASS);
});
}
// -----------------------------------------------------------------------------------------------------------------

View File

@ -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
{
protected ViewableData $original;
@ -13,6 +18,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;

View File

@ -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
{
@ -13,6 +15,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();
}