|
|
@@ -12,6 +12,7 @@ final class ArrayOfType extends AbstractType
|
|
|
|
|
|
private ?int $min = null;
|
|
|
private ?int $max = null;
|
|
|
+ private ?bool $acceptStringKeys = false;
|
|
|
|
|
|
public function min(int $min): self
|
|
|
{
|
|
|
@@ -25,6 +26,12 @@ final class ArrayOfType extends AbstractType
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ public function acceptStringKeys(): self
|
|
|
+ {
|
|
|
+ $this->acceptStringKeys = true;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
public function __construct(AbstractType $type)
|
|
|
{
|
|
|
$this->type = $type;
|
|
|
@@ -66,10 +73,13 @@ final class ArrayOfType extends AbstractType
|
|
|
}
|
|
|
|
|
|
foreach ($values as $key => $value) {
|
|
|
- if (!is_int($key)) {
|
|
|
+ if ($this->acceptStringKeys === false && !is_int($key)) {
|
|
|
$result->setError('All keys must be integers');
|
|
|
return;
|
|
|
}
|
|
|
+ if (is_string($key)) {
|
|
|
+ $key = trim($key);
|
|
|
+ }
|
|
|
$definitions[$key] = $this->type;
|
|
|
}
|
|
|
if (empty($definitions)) {
|