Skip to content

Commit 3d6c11e

Browse files
author
abluchet
committed
Avoid serializing "resources" in the normalization context
1 parent c4d2e17 commit 3d6c11e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/EventListener/SerializeListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Exception\RuntimeException;
1717
use ApiPlatform\Core\Serializer\SerializerContextBuilderInterface;
1818
use ApiPlatform\Core\Util\RequestAttributesExtractor;
19+
use ApiPlatform\Core\HttpCache\TagsArray;
1920
use Symfony\Component\HttpFoundation\Request;
2021
use Symfony\Component\HttpFoundation\Response;
2122
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
@@ -59,13 +60,13 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
5960
}
6061

6162
$context = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
62-
$resources = [];
63+
$resources = new TagsArray();
6364
$context['resources'] = &$resources;
6465

6566
$event->setControllerResult($this->serializer->serialize($controllerResult, $request->getRequestFormat(), $context));
6667

6768
$request->attributes->set('_api_respond', true);
68-
$request->attributes->set('_resources', $request->attributes->get('_resources', []) + $resources);
69+
$request->attributes->set('_resources', $request->attributes->get('_resources', []) + (array) $resources);
6970
}
7071

7172
/**

src/HttpCache/TagsArray.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\HttpCache;
15+
16+
/**
17+
* An ArrayObject that serializes to an empty string to store IRIs
18+
*
19+
* @author Antoine Bluchet <[email protected]>
20+
*/
21+
final class TagsArray extends \ArrayObject
22+
{
23+
public function serialize() {}
24+
}

0 commit comments

Comments
 (0)