-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced Param Converters with Value Resolvers
- Loading branch information
Showing
12 changed files
with
279 additions
and
349 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
Ibexa\Bundle\Core\ValueResolver\: | ||
resource: "../../ValueResolver/*" | ||
tags: | ||
- name: controller.argument_value_resolver | ||
priority: -2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\Core\ValueResolver; | ||
|
||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Content; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface; | ||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; | ||
|
||
final class ContentValueResolver implements ValueResolverInterface | ||
{ | ||
private const string ATTRIBUTE_CONTENT_ID = 'contentId'; | ||
|
||
public function __construct( | ||
private readonly ContentService $contentService | ||
) { | ||
} | ||
|
||
/** | ||
* @return iterable<\Ibexa\Contracts\Core\Repository\Values\Content\Content> | ||
* | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
if ($argument->getType() !== Content::class) { | ||
return []; | ||
} | ||
|
||
$contentId = $request->attributes->get(self::ATTRIBUTE_CONTENT_ID); | ||
|
||
if (!is_numeric($contentId)) { | ||
return []; | ||
} | ||
|
||
yield $this->contentService->loadContent((int)$contentId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\Core\ValueResolver; | ||
|
||
use Ibexa\Contracts\Core\Repository\LocationService; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Language; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Location; | ||
use Ibexa\Core\Helper\ContentPreviewHelper; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface; | ||
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; | ||
|
||
final class LocationValueResolver implements ValueResolverInterface | ||
{ | ||
private const string ATTRIBUTE_LOCATION_ID = 'locationId'; | ||
|
||
public function __construct( | ||
private readonly LocationService $locationService, | ||
private readonly ContentPreviewHelper $contentPreviewHelper | ||
) { | ||
} | ||
|
||
/** | ||
* @return iterable<\Ibexa\Contracts\Core\Repository\Values\Content\Location> | ||
* | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException | ||
*/ | ||
public function resolve(Request $request, ArgumentMetadata $argument): iterable | ||
{ | ||
if ($argument->getType() !== Location::class) { | ||
return []; | ||
} | ||
|
||
$locationId = $request->attributes->get(self::ATTRIBUTE_LOCATION_ID); | ||
|
||
if (!is_numeric($locationId)) { | ||
return []; | ||
} | ||
|
||
$prioritizedLanguages = $this->contentPreviewHelper->isPreviewActive() ? Language::ALL : null; | ||
|
||
yield $this->locationService->loadLocation((int)$locationId, $prioritizedLanguages); | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
tests/bundle/Core/Converter/AbstractParamConverterTest.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.