-
Notifications
You must be signed in to change notification settings - Fork 6
/
HomeController.php
42 lines (35 loc) · 1.27 KB
/
HomeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace AutoMapper\Tests\Bundle\Resources\App\Controller;
use AutoMapper\AutoMapperInterface;
use AutoMapper\Tests\Bundle\Resources\App\Entity\FooMapTo;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class HomeController extends AbstractController
{
public function __construct(
private AutoMapperInterface $autoMapper,
#[Autowire('@serializer.normalizer.object')]
private NormalizerInterface $serializer
) {
}
#[Route('/')]
public function __invoke(Request $request): Response
{
$output = [];
$data = new FooMapTo('value');
for ($i = 0; $i < 10000; ++$i) {
if ($request->query->has('serializer')) {
$output[] = $this->serializer->normalize($data, 'json');
} else {
$output[] = $this->autoMapper->map($data, 'array');
}
}
return new JsonResponse($output);
}
}