Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

QueryTypePass.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
8
9 use Exception;
10 use ReflectionClass;
11 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12 use Symfony\Component\DependencyInjection\ContainerBuilder;
13 use Symfony\Component\DependencyInjection\Definition;
14 use Symfony\Component\DependencyInjection\Reference;
15
19 class QueryTypePass implements CompilerPassInterface
20 {
21 public function process(ContainerBuilder $container)
22 {
23 if (!$container->hasDefinition('ezpublish.query_type.registry')) {
24 return;
25 }
26
27 $queryTypes = [];
28 $queryTypesClasses = [];
29
30 // tagged query types
31 $taggedServiceIds = $container->findTaggedServiceIds('ezpublish.query_type');
32 foreach ($taggedServiceIds as $taggedServiceId => $tags) {
33 $queryTypeDefinition = $container->getDefinition($taggedServiceId);
34 $queryTypeClass = $container->getParameterBag()->resolveValue($queryTypeDefinition->getClass());
35
36 $queryTypesClasses[$queryTypeClass] = [];
37
38 for ($i = 0, $count = count($tags); $i < $count; ++$i) {
39 $name = isset($tags[$i]['alias']) ? $tags[$i]['alias'] : $queryTypeClass::getName();
40 $queryTypes[$name] = new Reference($taggedServiceId);
41 $queryTypesClasses[$queryTypeClass][$name] = true;
42 }
43 }
44
45 // named by convention query types
46 if ($container->hasParameter('kernel.bundles')) {
47 foreach ($container->getParameter('kernel.bundles') as $bundleName => $bundleClass) {
48 $bundleReflectionClass = new ReflectionClass($bundleClass);
49 $bundleDir = dirname($bundleReflectionClass->getFileName());
50
51 $bundleQueryTypesDir = $bundleDir . \DIRECTORY_SEPARATOR . 'QueryType';
52
53 if (!is_dir($bundleQueryTypesDir)) {
54 continue;
55 }
56
57 $queryTypeServices = [];
58 $bundleQueryTypeNamespace = substr($bundleClass, 0, strrpos($bundleClass, '\\') + 1) . 'QueryType';
59 foreach (glob($bundleQueryTypesDir . \DIRECTORY_SEPARATOR . '*QueryType.php') as $queryTypeFilePath) {
60 $queryTypeFileName = basename($queryTypeFilePath, '.php');
61 $queryTypeClassName = $bundleQueryTypeNamespace . '\\' . $queryTypeFileName;
62 if (!class_exists($queryTypeClassName)) {
63 throw new Exception("Expected $queryTypeClassName to be defined in $queryTypeFilePath");
64 }
65
66 $queryTypeName = $queryTypeClassName::getName();
67
68 // skip if the class was already registered as a tagged service with the same name
69 if (isset($queryTypesClasses[$queryTypeClassName][$queryTypeName])) {
70 continue;
71 }
72
73 $queryTypeReflectionClass = new ReflectionClass($queryTypeClassName);
74 if (!$queryTypeReflectionClass->implementsInterface('eZ\Publish\Core\QueryType\QueryType')) {
75 throw new Exception("$queryTypeClassName needs to implement eZ\\Publish\\Core\\QueryType\\QueryType");
76 }
77
78 $serviceId = 'ezpublish.query_type.convention.' . strtolower($bundleName) . '_' . strtolower($queryTypeFileName);
79 $queryTypeServices[$serviceId] = new Definition($queryTypeClassName);
80
81 $queryTypes[$queryTypeName] = new Reference($serviceId);
82 }
83
84 $container->addDefinitions($queryTypeServices);
85 }
86 }
87
88 $aggregatorDefinition = $container->getDefinition('ezpublish.query_type.registry');
89 $aggregatorDefinition->addMethodCall('addQueryTypes', [$queryTypes]);
90 }
91 }
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\QueryTypePass
Processes services tagged as ezpublish.query_type, and registers them with ezpublish....
Definition: QueryTypePass.php:20
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\QueryTypePass\process
process(ContainerBuilder $container)
Definition: QueryTypePass.php:21
eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler
Definition: AsseticPass.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.