Skip to content

Commit b330f57

Browse files
committed
Made CriteriaConverter capable of using lazy constructors
1 parent 25907f7 commit b330f57

File tree

10 files changed

+51
-245
lines changed

10 files changed

+51
-245
lines changed

src/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPass.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/lib/Persistence/Legacy/URL/Query/CriteriaConverter.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,46 @@
99
use Doctrine\DBAL\Query\QueryBuilder;
1010
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException;
1111
use Ibexa\Contracts\Core\Repository\Values\URL\Query\Criterion;
12+
use Traversable;
1213

1314
class CriteriaConverter
1415
{
1516
/**
1617
* Criterion handlers.
1718
*
18-
* @var \Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler[]
19+
* @var iterable<\Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler>
1920
*/
20-
protected $handlers;
21+
protected iterable $handlers;
2122

2223
/**
2324
* Construct from an optional array of Criterion handlers.
2425
*
25-
* @param \Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler[] $handlers
26+
* @param iterable<\Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler> $handlers
2627
*/
27-
public function __construct(array $handlers = [])
28+
public function __construct(iterable $handlers = [])
2829
{
2930
$this->handlers = $handlers;
3031
}
3132

3233
/**
33-
* Adds handler.
34-
*
35-
* @param \Ibexa\Core\Persistence\Legacy\URL\Query\CriterionHandler $handler
34+
* @deprecated The "%s" method is deprecated. Use a service definition tag "ibexa.storage.legacy.url.criterion.handler" instead.
3635
*/
3736
public function addHandler(CriterionHandler $handler)
3837
{
38+
trigger_deprecation(
39+
'ibexa/core',
40+
'4.6.24',
41+
'The "%s" method is deprecated. Use a service definition tag ("%s") instead.',
42+
__METHOD__,
43+
implode('", "', [
44+
'ibexa.storage.legacy.url.criterion.handler',
45+
]),
46+
);
47+
48+
if ($this->handlers instanceof Traversable) {
49+
$this->handlers = iterator_to_array($this->handlers);
50+
}
51+
3952
$this->handlers[] = $handler;
4053
}
4154

src/lib/Resources/settings/search_engines/legacy/criterion_handlers_content.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
services:
2-
# Note: services tagged with:
3-
# - ibexa.search.legacy.gateway.criterion_handler.content
4-
# are registered to this one using compilation pass
52
ibexa.search.legacy.gateway.criteria_converter.content:
63
class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter
74
lazy: true
5+
arguments:
6+
$handlers: !tagged_iterator ibexa.search.legacy.gateway.criterion_handler.content
87

98
Ibexa\Core\Search\Legacy\Content\Gateway\CriterionHandler\Ancestor:
109
parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler

src/lib/Resources/settings/search_engines/legacy/criterion_handlers_location.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
services:
2-
# Note: services tagged with:
3-
# - ibexa.search.legacy.gateway.criterion_handler.location
4-
# are registered to this one using compilation pass
52
ibexa.search.legacy.gateway.criteria_converter.location:
63
class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter
74
lazy: true
5+
arguments:
6+
$handlers: !tagged_iterator ibexa.search.legacy.gateway.criterion_handler.location
87

98
Ibexa\Core\Search\Legacy\Content\Location\Gateway\CriterionHandler\Ancestor:
109
parent: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler

src/lib/Resources/settings/storage_engines/legacy/trash.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ services:
1212
ibexa.core.trash.search.legacy.gateway.criteria_converter:
1313
class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter
1414
lazy: true
15+
arguments:
16+
$handlers: !tagged_iterator ibexa.search.legacy.trash.gateway.criterion.handler
1517

1618
ibexa.core.trash.search.legacy.gateway.sort_clause_converter:
1719
class: Ibexa\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter

src/lib/Resources/settings/storage_engines/legacy/url.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ services:
2727
Ibexa\Core\Persistence\Legacy\URL\Query\CriteriaConverter:
2828
class: Ibexa\Core\Persistence\Legacy\URL\Query\CriteriaConverter
2929
lazy: true
30+
arguments:
31+
$handlers: !tagged_iterator ibexa.storage.legacy.url.criterion.handler

src/lib/Search/Legacy/Content/Common/Gateway/CriteriaConverter.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Doctrine\DBAL\Query\QueryBuilder;
1010
use Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException;
1111
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
12+
use Traversable;
1213

1314
/**
1415
* Content locator gateway implementation using the DoctrineDatabase.
@@ -20,25 +21,41 @@ class CriteriaConverter
2021
*
2122
* @var \Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler[]
2223
*/
23-
protected $handlers;
24+
protected iterable $handlers;
2425

2526
/**
2627
* Construct from an optional array of Criterion handlers.
2728
*
2829
* @param \Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler[] $handlers
2930
*/
30-
public function __construct(array $handlers = [])
31+
public function __construct(iterable $handlers = [])
3132
{
3233
$this->handlers = $handlers;
3334
}
3435

3536
/**
36-
* Adds handler.
37-
*
38-
* @param \Ibexa\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler $handler
37+
* @deprecated The "%s" method is deprecated. Use a service definition tag instead (one of
38+
* "ibexa.search.legacy.gateway.criterion_handler.content",
39+
* "ibexa.search.legacy.gateway.criterion_handler.location",
40+
* "ibexa.search.legacy.trash.gateway.criterion.handler").
3941
*/
4042
public function addHandler(CriterionHandler $handler)
4143
{
44+
trigger_deprecation(
45+
'ibexa/core',
46+
'4.6.24',
47+
'The "%s" method is deprecated. Use a service definition tag instead (one of "%s").',
48+
__METHOD__,
49+
implode('", "', [
50+
'ibexa.search.legacy.gateway.criterion_handler.content',
51+
'ibexa.search.legacy.gateway.criterion_handler.location',
52+
'ibexa.search.legacy.trash.gateway.criterion.handler',
53+
]),
54+
);
55+
56+
if ($this->handlers instanceof Traversable) {
57+
$this->handlers = iterator_to_array($this->handlers);
58+
}
4259
$this->handlers[] = $handler;
4360
}
4461

tests/integration/Core/LegacyTestContainerBuilder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ private function registerCompilerPasses(): void
124124
$this->addCompilerPass(new Compiler\Storage\Legacy\FieldValueConverterRegistryPass());
125125
$this->addCompilerPass(new Compiler\Storage\Legacy\RoleLimitationConverterPass());
126126

127-
$this->addCompilerPass(new Compiler\Search\Legacy\CriteriaConverterPass());
128127
$this->addCompilerPass(new Compiler\Search\Legacy\CriterionFieldValueHandlerRegistryPass());
129128
$this->addCompilerPass(new Compiler\Search\Legacy\SortClauseConverterPass());
130129

tests/lib/Base/Container/Compiler/Search/Legacy/CriteriaConverterPassTest.php

Lines changed: 0 additions & 154 deletions
This file was deleted.

tests/lib/Persistence/Legacy/HandlerTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,7 @@ public function testTransactionHandlerTwice(): void
227227

228228
protected function getHandlerFixture(): Handler
229229
{
230-
if (!isset(self::$legacyHandler)) {
231-
$container = $this->getContainer();
232-
233-
self::$legacyHandler = $container->get(Handler::class);
234-
}
235-
236-
return self::$legacyHandler;
230+
return self::$legacyHandler ??= $this->getContainer()->get(Handler::class);
237231
}
238232

239233
protected static Container $container;

0 commit comments

Comments
 (0)