Skip to content

Commit

Permalink
Replaced Param Converters with Value Resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Jan 3, 2025
1 parent a1ed98d commit e426c69
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 349 deletions.
37 changes: 0 additions & 37 deletions src/bundle/Core/Converter/ContentParamConverter.php

This file was deleted.

50 changes: 0 additions & 50 deletions src/bundle/Core/Converter/LocationParamConverter.php

This file was deleted.

54 changes: 0 additions & 54 deletions src/bundle/Core/Converter/RepositoryParamConverter.php

This file was deleted.

20 changes: 1 addition & 19 deletions src/bundle/Core/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
imports:
- { resource: commands.yml }
- { resource: value_resolvers.yaml }

parameters:
ibexa.site_access.default.name: default
ibexa.config.default_scope: ibexa.site_access.config

# Param converters
ibexa.param_converter.content.priority: -2
ibexa.param_converter.location.priority: -2

services:
# Siteaccess is injected in the container at runtime
Ibexa\Core\MVC\Symfony\SiteAccess:
Expand Down Expand Up @@ -183,21 +180,6 @@ services:
tags:
- { name: kernel.fragment_renderer, alias: !php/const Ibexa\Bundle\Core\Fragment\DirectFragmentRenderer::NAME }

Ibexa\Bundle\Core\Converter\ContentParamConverter:
class: Ibexa\Bundle\Core\Converter\ContentParamConverter
arguments:
- '@ibexa.siteaccessaware.service.content'
tags:
- { name: request.param_converter, priority: '%ibexa.param_converter.content.priority%', converter: ez_content_converter }

Ibexa\Bundle\Core\Converter\LocationParamConverter:
class: Ibexa\Bundle\Core\Converter\LocationParamConverter
arguments:
$locationService: '@ibexa.siteaccessaware.service.location'
$contentPreviewHelper: '@Ibexa\Core\Helper\ContentPreviewHelper'
tags:
- { name: request.param_converter, priority: '%ibexa.param_converter.location.priority%', converter: ez_location_converter }

Ibexa\Bundle\Core\ControllerArgumentResolver\LocationArgumentResolver:
autowire: true
autoconfigure: true
Expand Down
11 changes: 11 additions & 0 deletions src/bundle/Core/Resources/config/value_resolvers.yaml
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
46 changes: 46 additions & 0 deletions src/bundle/Core/ValueResolver/ContentValueResolver.php
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);
}
}
51 changes: 51 additions & 0 deletions src/bundle/Core/ValueResolver/LocationValueResolver.php
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 tests/bundle/Core/Converter/AbstractParamConverterTest.php

This file was deleted.

Loading

0 comments on commit e426c69

Please sign in to comment.