Browse Source

fix ItemType validator

phpdevcommunity 1 month ago
parent
commit
313f7d6ea9
3 changed files with 8 additions and 2 deletions
  1. 1 0
      .gitignore
  2. 1 1
      src/Schema/AbstractSchema.php
  3. 6 1
      src/Type/ItemType.php

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 /.idea
 /vendor
+composer.lock

+ 1 - 1
src/Schema/AbstractSchema.php

@@ -96,7 +96,7 @@ abstract class AbstractSchema
      */
     abstract protected function definitions(): array;
 
-    final private function getDefinitions(): array
+    private function getDefinitions(): array
     {
         $definitions = $this->definitions();
         foreach ($definitions as $definition) {

+ 6 - 1
src/Type/ItemType.php

@@ -38,8 +38,13 @@ final class ItemType extends AbstractType
 
     protected function validateValue(ValidationResult $result): void
     {
+        $value = $result->getValue();
+        if (!is_array($value)) {
+            $result->setError("Value must be an array, got: " . gettype($result->getValue()));
+            return;
+        }
         try {
-            $result->setValue($this->schema->process($result->getValue()));
+            $result->setValue($this->schema->process($value));
         } catch (InvalidDataException $e) {
             $result->setErrors($e->getErrors(), false);
         }