-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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,37 @@ | ||
<?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\Rest\Server\Input\Parser\Criterion; | ||
|
||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer as IsContainerCriterion; | ||
use Ibexa\Contracts\Rest\Exceptions; | ||
use Ibexa\Contracts\Rest\Input\ParsingDispatcher; | ||
use Ibexa\Rest\Input\BaseParser; | ||
use Ibexa\Rest\Input\ParserTools; | ||
|
||
final class IsContainer extends BaseParser | ||
{ | ||
private ParserTools $parserTools; | ||
|
||
public function __construct(ParserTools $parserTools) | ||
{ | ||
$this->parserTools = $parserTools; | ||
} | ||
|
||
/** | ||
* @param array<mixed> $data | ||
*/ | ||
public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsContainerCriterion | ||
{ | ||
if (!array_key_exists('IsContainerCriterion', $data)) { | ||
throw new Exceptions\Parser('Invalid <IsContainer> format'); | ||
} | ||
|
||
return new IsContainerCriterion($this->parserTools->parseBooleanValue($data['IsContainerCriterion'])); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php
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,40 @@ | ||
<?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\Tests\Bundle\Rest\Functional\SearchView\Criterion; | ||
|
||
use Ibexa\Tests\Bundle\Rest\Functional\SearchView\SearchCriterionTestCase; | ||
|
||
final class IsContainerTest extends SearchCriterionTestCase | ||
{ | ||
/** | ||
* @phpstan-return iterable< | ||
* string, | ||
* array{ | ||
* string, | ||
* string, | ||
* int, | ||
* }, | ||
* > | ||
*/ | ||
public function getCriteriaPayloads(): iterable | ||
{ | ||
return [ | ||
'is container' => [ | ||
'json', | ||
$this->buildJsonCriterionQuery('"IsContainerCriterion": true'), | ||
10, | ||
], | ||
'is not container' => [ | ||
'json', | ||
$this->buildJsonCriterionQuery('"IsContainerCriterion": false'), | ||
2, | ||
], | ||
]; | ||
} | ||
} |