Skip to content
Snippets Groups Projects
Commit 8d956fe9 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

Merge branch 'PTPS_Controller_3' into PTPS_Controller_4

parents 41240ef5 6274eb5d
No related branches found
No related tags found
1 merge request!4Ptps controller 4
......@@ -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
......@@ -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'])]
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment