Skip to content

Commit

Permalink
Moved LocationArgumentResolver to ControllerArgumentResolved namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Oct 10, 2023
1 parent 2deba4c commit aefa53c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/
declare(strict_types=1);

namespace Ibexa\Bundle\Core\Converter;
namespace Ibexa\Bundle\Core\ControllerArgumentResolver;

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
Expand All @@ -30,7 +31,9 @@ public function __construct(LocationService $locationService)

public function supports(Request $request, ArgumentMetadata $argument): bool
{
return !$request->attributes->has(self::PARAMETER_LOCATION_ID)
return
Location::class === $argument->getType()
&& !$request->attributes->has(self::PARAMETER_LOCATION_ID)
&& $request->query->has(self::PARAMETER_LOCATION_ID);
}

Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Core/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ services:
tags:
- { name: request.param_converter, priority: '%ibexa.param_converter.location.priority%', converter: ez_location_converter }

Ibexa\Bundle\Core\Converter\LocationArgumentResolver:
Ibexa\Bundle\Core\ControllerArgumentResolver\LocationArgumentResolver:
autowire: true
autoconfigure: true
tags:
- { name: controller.argument_value_resolver, priority: '%ibexa.param_converter.location.priority%' }
- { name: controller.argument_value_resolver, priority: 50 }

Ibexa\Bundle\Core\EventListener\ExceptionListener:
class: Ibexa\Bundle\Core\EventListener\ExceptionListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\Core\Converter;
namespace Ibexa\Tests\Bundle\Core\ControllerArgumentResolver;

use Generator;
use Ibexa\Bundle\Core\Converter\LocationArgumentResolver;
use Ibexa\Bundle\Core\ControllerArgumentResolver\LocationArgumentResolver;
use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
Expand Down Expand Up @@ -96,27 +96,44 @@ public function testResolve(): void
*/
public function provideDataForTestSupports(): iterable
{
$argumentMetadata = $this->createMock(ArgumentMetadata::class);
$locationBasedArgumentMetadata = $this->createArgumentMetadata(Location::class);

yield 'Supported - locationId passed to request query' => [
true,
$this->createRequest(true, false, 1),
$argumentMetadata,
$locationBasedArgumentMetadata,
];

yield 'Not supported - type different than Ibexa\Contracts\Core\Repository\Values\Content\Location' => [
false,
$this->createRequest(true, false, 1),
$this->createArgumentMetadata('foo'),
];

yield 'Not supported - locationId passed to request attributes' => [
false,
$this->createRequest(false, true, 1),
$argumentMetadata,
$locationBasedArgumentMetadata,
];

yield 'Not supported - locationId passed to request attributes and query' => [
false,
$this->createRequest(true, true, 1),
$argumentMetadata,
$locationBasedArgumentMetadata,
];
}

private function createArgumentMetadata(string $type): ArgumentMetadata
{
$argumentMetadata = $this->createMock(ArgumentMetadata::class);
$argumentMetadata
->expects(self::atLeastOnce())
->method('getType')
->willReturn($type);

return $argumentMetadata;
}

private function createRequest(
bool $addToQuery,
bool $addToAttributes,
Expand Down

0 comments on commit aefa53c

Please sign in to comment.