Loading src/Controller/HomeController.php +1 −5 Original line number Diff line number Diff line Loading @@ -41,14 +41,10 @@ class HomeController extends AbstractController return $this->json($result); } #[Route('/', name: 'home', methods: ['POST'])] #[Route('/func3', name: 'home', methods: ['POST'])] public function home(Request $request): Response { $array = $request->get('arr'); $errors = ArrayValidation::validate($array); if (count($errors) > 0) { return new Response((string)$errors); } $result = $this->functions->uniqElements($array); return $this->json($result); } Loading src/Validation/ArrayValidation.php +0 −17 Original line number Diff line number Diff line Loading @@ -17,21 +17,4 @@ class ArrayValidation $ages = array_column($array, 'age'); return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages)); } public static function validate(array $array): ConstraintViolationListInterface { $validator = Validation::createValidator(); $constraints = new Assert\Optional([ new Assert\Collection([ new Assert\Optional([ new Assert\Type('array'), new Assert\Collection([ new Assert\Type('string'), new Assert\Type('string'), ]) ]) ]) ]); return $validator->validate($array, $constraints); } } No newline at end of file Loading
src/Controller/HomeController.php +1 −5 Original line number Diff line number Diff line Loading @@ -41,14 +41,10 @@ class HomeController extends AbstractController return $this->json($result); } #[Route('/', name: 'home', methods: ['POST'])] #[Route('/func3', name: 'home', methods: ['POST'])] public function home(Request $request): Response { $array = $request->get('arr'); $errors = ArrayValidation::validate($array); if (count($errors) > 0) { return new Response((string)$errors); } $result = $this->functions->uniqElements($array); return $this->json($result); } Loading
src/Validation/ArrayValidation.php +0 −17 Original line number Diff line number Diff line Loading @@ -17,21 +17,4 @@ class ArrayValidation $ages = array_column($array, 'age'); return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages)); } public static function validate(array $array): ConstraintViolationListInterface { $validator = Validation::createValidator(); $constraints = new Assert\Optional([ new Assert\Collection([ new Assert\Optional([ new Assert\Type('array'), new Assert\Collection([ new Assert\Type('string'), new Assert\Type('string'), ]) ]) ]) ]); return $validator->validate($array, $constraints); } } No newline at end of file