diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 50ac5d2c506..83e78a20dcc 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -101,3 +101,4 @@ parameters: - '#Method ApiPlatform\\Core\\DataProvider\\CollectionDataProviderInterface::getCollection\(\) invoked with 3 parameters, 1-2 required\.#' - '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize\(\) invoked with 3 parameters, 1 required\.#' - '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::normalize\(\) invoked with 4 parameters, 1 required\.#' + - '#Class Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener constructor invoked with 5 parameters, 1-3 required\.#' diff --git a/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig b/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig index e5983280b4e..79d78a25bf2 100644 --- a/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig +++ b/src/Bridge/Symfony/Bundle/Resources/views/DataCollector/request.html.twig @@ -164,11 +164,13 @@ - {% for key, value in collector.resourceMetadata.attributes if key != 'filters' %} - - {{ key }} - {{- profiler_dump(value, 2) -}} - + {% for key, value in collector.resourceMetadata.attributes %} + {% if key != 'filters' %} + + {{ key }} + {{- profiler_dump(value, 2) -}} + + {% endif %} {% endfor %} diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 61a2b2984e0..145987d6270 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -14,6 +14,7 @@ namespace ApiPlatform\Core\EventListener; use ApiPlatform\Core\Util\RequestAttributesExtractor; +use Psr\Log\LoggerInterface; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener; @@ -23,8 +24,15 @@ * @author Samuel ROZE * @author Kévin Dunglas */ -final class ExceptionListener extends BaseExceptionListener +final class ExceptionListener { + private $exceptionListener; + + public function __construct($controller, LoggerInterface $logger = null, $debug = false, string $charset = null, $fileLinkFormat = null) + { + $this->exceptionListener = new BaseExceptionListener($controller, $logger, $debug, $charset, $fileLinkFormat); + } + public function onKernelException(GetResponseForExceptionEvent $event): void { $request = $event->getRequest(); @@ -36,6 +44,6 @@ public function onKernelException(GetResponseForExceptionEvent $event): void return; } - parent::onKernelException($event); + $this->exceptionListener->onKernelException($event); } } diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index cee26df831c..67951a86ec7 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -396,7 +396,7 @@ protected function denormalizeCollection(string $attribute, PropertyMetadata $pr ); } - $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute)); + $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute, $format)); } return $values; @@ -531,7 +531,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array $this->resourceClassResolver->isResourceClass($className) ) { $resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className); - $childContext = $this->createChildContext($context, $attribute); + $childContext = $this->createChildContext($context, $attribute, $format); $childContext['resource_class'] = $resourceClass; return $this->normalizeCollectionOfRelations($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext); @@ -543,7 +543,7 @@ protected function getAttributeValue($object, $attribute, $format = null, array $this->resourceClassResolver->isResourceClass($className) ) { $resourceClass = $this->resourceClassResolver->getResourceClass($attributeValue, $className); - $childContext = $this->createChildContext($context, $attribute); + $childContext = $this->createChildContext($context, $attribute, $format); $childContext['resource_class'] = $resourceClass; return $this->normalizeRelation($propertyMetadata, $attributeValue, $resourceClass, $format, $childContext); @@ -660,7 +660,7 @@ private function createAttributeValue($attribute, $value, $format = null, array $this->resourceClassResolver->isResourceClass($className) ) { $resourceClass = $this->resourceClassResolver->getResourceClass(null, $className); - $childContext = $this->createChildContext($context, $attribute); + $childContext = $this->createChildContext($context, $attribute, $format); $childContext['resource_class'] = $resourceClass; return $this->denormalizeRelation($attribute, $propertyMetadata, $resourceClass, $value, $format, $childContext); diff --git a/tests/Fixtures/app/AppKernel.php b/tests/Fixtures/app/AppKernel.php index f7e09ae561b..87a7fd3f4ef 100644 --- a/tests/Fixtures/app/AppKernel.php +++ b/tests/Fixtures/app/AppKernel.php @@ -29,6 +29,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\RouteCollectionBuilder; +use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder; use Symfony\Component\Security\Core\User\UserInterface; /** @@ -96,10 +97,11 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load $loader->load(__DIR__."/config/config_{$this->getEnvironment()}.yml"); + $alg = class_exists(SodiumPasswordEncoder::class) && SodiumPasswordEncoder::isSupported() ? 'auto' : 'bcrypt'; $securityConfig = [ 'encoders' => [ - User::class => 'bcrypt', - UserDocument::class => 'bcrypt', + User::class => $alg, + UserDocument::class => $alg, // Don't use plaintext in production! UserInterface::class => 'plaintext', ], @@ -128,6 +130,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'provider' => 'chain_provider', 'http_basic' => null, 'anonymous' => null, + 'logout_on_user_change' => true, ], ], 'access_control' => [