Skip to content

Commit 6292902

Browse files
authored
IBX-10458: Implemented new Content Type search PHP API (#633)
1 parent 2ba7fdf commit 6292902

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1581
-9
lines changed

.github/workflows/browser-tests.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ jobs:
1717
test-suite: "--mode=standard --profile=core --tags='~@broken&&~@setup'"
1818
secrets:
1919
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
20+
AUTOMATION_CLIENT_ID: ${{ secrets.AUTOMATION_CLIENT_ID }}
21+
AUTOMATION_CLIENT_INSTALLATION: ${{ secrets.AUTOMATION_CLIENT_INSTALLATION }}
22+
AUTOMATION_CLIENT_SECRET: ${{ secrets.AUTOMATION_CLIENT_SECRET }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Persistence\Content\Type;
10+
11+
use Doctrine\DBAL\Query\QueryBuilder;
12+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
13+
use Ibexa\Core\Persistence\Legacy\Content\Type\Gateway\CriterionVisitor\CriterionVisitor;
14+
15+
/**
16+
* @template TCriterion of \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface
17+
*/
18+
interface CriterionHandlerInterface
19+
{
20+
/**
21+
* @phpstan-param TCriterion $criterion
22+
*/
23+
public function supports(CriterionInterface $criterion): bool;
24+
25+
/**
26+
* @phpstan-param TCriterion $criterion
27+
*
28+
* @return string|\Doctrine\DBAL\Query\Expression\CompositeExpression
29+
*/
30+
public function apply(
31+
CriterionVisitor $criterionVisitor,
32+
QueryBuilder $qb,
33+
CriterionInterface $criterion
34+
);
35+
}

src/contracts/Persistence/Content/Type/Handler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Ibexa\Contracts\Core\Persistence\Content\Type;
1010
use Ibexa\Contracts\Core\Persistence\Content\Type\Group\CreateStruct as GroupCreateStruct;
1111
use Ibexa\Contracts\Core\Persistence\Content\Type\Group\UpdateStruct as GroupUpdateStruct;
12+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
1213

1314
interface Handler
1415
{
@@ -91,6 +92,13 @@ public function loadContentTypes($groupId, $status = Type::STATUS_DEFINED);
9192
*/
9293
public function loadContentTypeList(array $contentTypeIds): array;
9394

95+
/**
96+
* @param list<string> $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
97+
*
98+
* @return array{count: int, items: array<string, mixed>}
99+
*/
100+
public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): array;
101+
94102
/**
95103
* @return \Ibexa\Contracts\Core\Persistence\Content\Type[]
96104
*/

src/contracts/Repository/ContentTypeService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
1919
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
2020
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
21+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
22+
use Ibexa\Contracts\Core\Repository\Values\ContentType\SearchResult;
2123
use Ibexa\Contracts\Core\Repository\Values\User\User;
2224

2325
interface ContentTypeService
@@ -173,6 +175,11 @@ public function loadContentTypeDraft(int $contentTypeId, bool $ignoreOwnership =
173175
*/
174176
public function loadContentTypeList(array $contentTypeIds, array $prioritizedLanguages = []): iterable;
175177

178+
/**
179+
* @param list<string> $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
180+
*/
181+
public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): SearchResult;
182+
176183
/**
177184
* Get content type objects which belong to the given content type group.
178185
*

src/contracts/Repository/Decorator/ContentTypeServiceDecorator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition;
2020
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
2121
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
22+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\ContentTypeQuery;
23+
use Ibexa\Contracts\Core\Repository\Values\ContentType\SearchResult;
2224
use Ibexa\Contracts\Core\Repository\Values\User\User;
2325

2426
abstract class ContentTypeServiceDecorator implements ContentTypeService
@@ -107,6 +109,11 @@ public function loadContentTypeList(
107109
return $this->innerService->loadContentTypeList($contentTypeIds, $prioritizedLanguages);
108110
}
109111

112+
public function findContentTypes(?ContentTypeQuery $query = null, array $prioritizedLanguages = []): SearchResult
113+
{
114+
return $this->innerService->findContentTypes($query, $prioritizedLanguages);
115+
}
116+
110117
public function loadContentTypes(
111118
ContentTypeGroup $contentTypeGroup,
112119
array $prioritizedLanguages = []
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query;
10+
11+
final class ContentTypeQuery
12+
{
13+
public const DEFAULT_LIMIT = 25;
14+
15+
private ?CriterionInterface $criterion;
16+
17+
/** @var \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] */
18+
private array $sortClauses;
19+
20+
private int $offset;
21+
22+
private ?int $limit;
23+
24+
/**
25+
* @param \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[] $sortClauses
26+
*/
27+
public function __construct(
28+
?CriterionInterface $criterion = null,
29+
array $sortClauses = [],
30+
int $offset = 0,
31+
?int $limit = self::DEFAULT_LIMIT
32+
) {
33+
$this->criterion = $criterion;
34+
$this->sortClauses = $sortClauses;
35+
$this->offset = $offset;
36+
$this->limit = $limit;
37+
}
38+
39+
public function getCriterion(): ?CriterionInterface
40+
{
41+
return $this->criterion;
42+
}
43+
44+
public function setCriterion(?CriterionInterface $criterion): void
45+
{
46+
$this->criterion = $criterion;
47+
}
48+
49+
public function addSortClause(SortClause $sortClause): void
50+
{
51+
$this->sortClauses[] = $sortClause;
52+
}
53+
54+
/**
55+
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\Query\SortClause[]
56+
*/
57+
public function getSortClauses(): array
58+
{
59+
return $this->sortClauses;
60+
}
61+
62+
public function getOffset(): int
63+
{
64+
return $this->offset;
65+
}
66+
67+
public function setOffset(int $offset): void
68+
{
69+
$this->offset = $offset;
70+
}
71+
72+
public function getLimit(): ?int
73+
{
74+
return $this->limit;
75+
}
76+
77+
public function setLimit(?int $limit): void
78+
{
79+
$this->limit = $limit;
80+
}
81+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
12+
13+
final class ContainsFieldDefinitionId implements CriterionInterface
14+
{
15+
/** @var list<int>|int */
16+
private $value;
17+
18+
/**
19+
* @param list<int>|int $value
20+
*/
21+
public function __construct($value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<int>|int
28+
*/
29+
public function getValue()
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<int>|int $value
36+
*/
37+
public function setValue($value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
12+
13+
final class ContentTypeGroupId implements CriterionInterface
14+
{
15+
/** @var list<int>|int */
16+
private $value;
17+
18+
/**
19+
* @param list<int>|int $value
20+
*/
21+
public function __construct($value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<int>|int
28+
*/
29+
public function getValue()
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<int>|int $value
36+
*/
37+
public function setValue($value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
12+
13+
final class ContentTypeId implements CriterionInterface
14+
{
15+
/** @var list<int>|int */
16+
private $value;
17+
18+
/**
19+
* @param list<int>|int $value
20+
*/
21+
public function __construct($value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<int>|int
28+
*/
29+
public function getValue()
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<int>|int $value
36+
*/
37+
public function setValue($value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Contracts\Core\Repository\Values\ContentType\Query\Criterion;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\ContentType\Query\CriterionInterface;
12+
13+
final class ContentTypeIdentifier implements CriterionInterface
14+
{
15+
/** @var list<string>|string */
16+
private $value;
17+
18+
/**
19+
* @param list<string>|string $value
20+
*/
21+
public function __construct($value)
22+
{
23+
$this->value = $value;
24+
}
25+
26+
/**
27+
* @return list<string>|string
28+
*/
29+
public function getValue()
30+
{
31+
return $this->value;
32+
}
33+
34+
/**
35+
* @param list<string>|string $value
36+
*/
37+
public function setValue($value): void
38+
{
39+
$this->value = $value;
40+
}
41+
}

0 commit comments

Comments
 (0)