Skip to content

Commit

Permalink
Used BaseCriterionProcessor from ibexa/rest
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Jul 17, 2024
1 parent 84062f1 commit a3a2238
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@

namespace Ibexa\Bundle\AdminUi\ControllerArgumentResolver;

use Ibexa\AdminUi\REST\Input\Parser\CriterionProcessorInterface;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LogicalAnd;
use Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\CriterionProcessorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

/**
* @phpstan-import-type TCriterionProcessor from \Ibexa\AdminUi\REST\Input\Parser\CriterionProcessor
*/
final class ContentTreeChildrenQueryArgumentResolver implements ArgumentValueResolverInterface
{
/** @phpstan-var TCriterionProcessor */
private CriterionProcessorInterface $criterionProcessor;

/**
* @phpstan-param TCriterionProcessor $criterionProcessor
*/
public function __construct(
CriterionProcessorInterface $criterionProcessor
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ services:
- { name: controller.argument_value_resolver, priority: 50 }

Ibexa\Bundle\AdminUi\ControllerArgumentResolver\ContentTreeChildrenQueryArgumentResolver:
arguments:
$criterionProcessor: '@Ibexa\AdminUi\REST\Input\Parser\CriterionProcessor'
tags:
- { name: controller.argument_value_resolver, priority: 50 }
5 changes: 1 addition & 4 deletions src/bundle/Resources/config/services/rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,5 @@ services:
- { name: ibexa.rest.output.value_object.visitor, type: Ibexa\AdminUi\REST\Value\ApplicationConfig }

Ibexa\AdminUi\REST\Input\Parser\CriterionProcessor:
arguments:
$parsingDispatcher: '@Ibexa\Contracts\Rest\Input\ParsingDispatcher'
parent: Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\BaseCriterionProcessor

Ibexa\AdminUi\REST\Input\Parser\CriterionProcessorInterface:
alias: Ibexa\AdminUi\REST\Input\Parser\CriterionProcessor
34 changes: 34 additions & 0 deletions src/lib/REST/Input/Parser/CriterionProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/

namespace Ibexa\AdminUi\REST\Input\Parser;

use Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\BaseCriterionProcessor;

/**
* @phpstan-type TCriterionProcessor \Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\CriterionProcessorInterface<
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
* >
*
* @extends \Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\BaseCriterionProcessor<
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
* >
*
* @internal
*/
final class CriterionProcessor extends BaseCriterionProcessor
{
protected function getMediaTypePrefix(): string
{
return 'application/vnd.ibexa.api.internal.criterion.';
}

protected function getParserInvalidCriterionMessage(string $criterionName): string
{
return "Invalid Criterion <$criterionName>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@

use ArrayIterator;
use Generator;
use Ibexa\AdminUi\REST\Input\Parser\CriterionProcessorInterface;
use Ibexa\Bundle\AdminUi\ControllerArgumentResolver\ContentTreeChildrenQueryArgumentResolver;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LogicalAnd;
use Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\CriterionProcessorInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Traversable;

/**
* @phpstan-type TCriterionProcessor \Ibexa\Contracts\Rest\Input\Parser\Query\Criterion\CriterionProcessorInterface<
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
* >
*
* @covers \Ibexa\Bundle\AdminUi\ControllerArgumentResolver\ContentTreeChildrenQueryArgumentResolver
*/
final class ContentTreeChildrenQueryArgumentResolverTest extends TestCase
{
private ArgumentValueResolverInterface $resolver;

/** @var \Ibexa\AdminUi\REST\Input\Parser\CriterionProcessorInterface&\PHPUnit\Framework\MockObject\MockObject */
/** @phpstan-var TCriterionProcessor&\PHPUnit\Framework\MockObject\MockObject */
private CriterionProcessorInterface $criterionProcessor;

protected function setUp(): void
Expand Down

0 comments on commit a3a2238

Please sign in to comment.