Added exception for enumerated array (#9644)

\SilverStripe\View\ArrayData::__construct() throws error when passed an enumerated array #9644
This commit is contained in:
Dylan Grech 2020-08-22 13:48:59 +02:00 committed by GitHub
parent 009ae3ee4f
commit a380cc7444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -33,10 +33,16 @@ class ArrayData extends ViewableData
{
if (is_object($value)) {
$this->array = get_object_vars($value);
} elseif (ArrayLib::is_associative($value)) {
$this->array = $value;
} elseif (is_array($value) && count($value) === 0) {
$this->array = [];
} elseif (is_array($value)) {
if (ArrayLib::is_associative($value)) {
$this->array = $value;
} elseif (count($value) === 0) {
$this->array = array();
} else {
$message = 'Parameter to ArrayData constructor needs to be an object or associative array,
enumareted array passed instead. Did you mean to use ArrayList?';
throw new InvalidArgumentException($message);
}
} else {
$message = 'Parameter to ArrayData constructor needs to be an object or associative array';
throw new InvalidArgumentException($message);