for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the OpenapiBundle package.
*
* (c) Niels Nijens <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nijens\OpenapiBundle\Deserialization\ArgumentResolver;
use Nijens\OpenapiBundle\Deserialization\Attribute\DeserializedObject;
use Nijens\OpenapiBundle\Deserialization\DeserializationContext;
use Nijens\OpenapiBundle\Routing\RouteContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
class DeserializedObjectArgumentResolver implements ArgumentValueResolverInterface
{
public function supports(Request $request, ArgumentMetadata $argument): bool
if ($request->attributes->has(DeserializationContext::REQUEST_ATTRIBUTE) === false) {
return false;
}
$routeContext = $request->attributes->get(RouteContext::REQUEST_ATTRIBUTE);
if (isset($routeContext[RouteContext::DESERIALIZATION_OBJECT]) === false) {
if ($routeContext[RouteContext::DESERIALIZATION_OBJECT] !== $argument->getType() && $this->hasDeserializedObjectAttribute($argument) === false) {
return true;
public function resolve(Request $request, ArgumentMetadata $argument): iterable
yield $request->attributes->get(DeserializationContext::REQUEST_ATTRIBUTE);
private function hasDeserializedObjectAttribute(ArgumentMetadata $argument): bool
if (method_exists($argument, 'getAttributes')) {
return count($argument->getAttributes(DeserializedObject::class, ArgumentMetadata::IS_INSTANCEOF)) === 0;