diff --git a/src/Action/Functions.php b/src/Action/Functions.php index d453447b3d12891707bcda1895237a22a62e3203..a0b7ad43bd10cbbebb60db6e2ba4a53efa1265e9 100644 --- a/src/Action/Functions.php +++ b/src/Action/Functions.php @@ -65,13 +65,13 @@ class Functions } /** - * Выходной маÑÑив: - * Array ( - * [0] => Array([0] => laravel, [1] => php) - * [1] => Array([0] => codeigniter, [1] => php) - * [3] => Array([0] => c++, [1] => java)) - * ) - */ + * Выходной маÑÑив: + * Array ( + * [0] => Array([0] => laravel, [1] => php) + * [1] => Array([0] => codeigniter, [1] => php) + * [3] => Array([0] => c++, [1] => java)) + * ) + */ /** * Сгруппировать подразедлы в верхние разделы меню @@ -137,5 +137,4 @@ class Functions * ['name' => 'ПоÑуда','depth' => 1,],]], * ]; */ -} - +} \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 92bf56a7abd23a36f3b9a278e3dc8f401fb1c61d..a897848b3987cf7b8ab47720e14aa738349dc317 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -7,15 +7,25 @@ use App\Validation\ArrayValidation; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - private Functions $functions; + private function uniqElements(array $array): array { + return array_unique($array, SORT_REGULAR); + } - public function __construct(Functions $functions) + #[Route('/', name: 'home')] + public function home(): Response { - $this->functions = $functions; + $arr = [ + ['laravel', 'php'], + ['codeigniter', 'php'], + ['laravel', 'php'], + ['c++', 'java'], + ]; + return $this->json($this->uniqElements($arr)); } #[Route('/', name: 'home', methods: ['POST'])] diff --git a/src/Validation/ArrayValidation.php b/src/Validation/ArrayValidation.php index 83567bdcb11f0d1fac13954fc54e7ddf09179ac0..e160dfbc9930c0b407ccd8f80d2315af5f1cc015 100644 --- a/src/Validation/ArrayValidation.php +++ b/src/Validation/ArrayValidation.php @@ -2,12 +2,22 @@ namespace App\Validation; -use Symfony\Component\Validator\Validation; -use Symfony\Component\Validator\Constraints as Assert; -use Symfony\Component\Validator\ConstraintViolationListInterface; - class ArrayValidation { + public static function validateFunc1(array $array): bool + { + $prices = array_column($array, 'price'); + $counts = array_column($array, 'count'); + return ctype_digit(implode('',$prices)) && ctype_digit(implode('', $counts)); + } + + public static function validateFunc2(array $array): bool + { + $ids = array_column($array, 'id'); + $ages = array_column($array, 'age'); + return ctype_digit(implode('', $ids)) && ctype_digit(implode('', $ages)); + } + public static function validate(array $array): ConstraintViolationListInterface { $validator = Validation::createValidator();