|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the API Platform project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Injects query extensions. |
|
22
|
|
|
* |
|
23
|
|
|
* @internal |
|
24
|
|
|
* |
|
25
|
|
|
* @author Samuel ROZE <[email protected]> |
|
26
|
|
|
* @author Kévin Dunglas <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
final class DoctrineQueryExtensionPass implements CompilerPassInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use PriorityTaggedServiceTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function process(ContainerBuilder $container) |
|
36
|
|
|
{ |
|
37
|
|
|
// if doctrine not loaded |
|
38
|
|
|
if (!$container->hasDefinition('api_platform.doctrine.metadata_factory')) { |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$collectionDataProviderDefinition = $container->getDefinition('api_platform.doctrine.orm.collection_data_provider'); |
|
43
|
|
|
$itemDataProviderDefinition = $container->getDefinition('api_platform.doctrine.orm.item_data_provider'); |
|
44
|
|
|
$subresourceDataProviderDefinition = $container->getDefinition('api_platform.doctrine.orm.subresource_data_provider'); |
|
45
|
|
|
|
|
46
|
|
|
$collectionExtensions = $this->findAndSortTaggedServices('api_platform.doctrine.orm.query_extension.collection', $container); |
|
47
|
|
|
$itemExtensions = $this->findAndSortTaggedServices('api_platform.doctrine.orm.query_extension.item', $container); |
|
48
|
|
|
|
|
49
|
|
|
$collectionDataProviderDefinition->replaceArgument(1, $collectionExtensions); |
|
50
|
|
|
$itemDataProviderDefinition->replaceArgument(3, $itemExtensions); |
|
51
|
|
|
$subresourceDataProviderDefinition->replaceArgument(3, $collectionExtensions); |
|
52
|
|
|
$subresourceDataProviderDefinition->replaceArgument(4, $itemExtensions); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|