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

OutputVisitorPass.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishRestBundle\DependencyInjection\Compiler;
8
9 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10 use Symfony\Component\DependencyInjection\ContainerBuilder;
11 use Symfony\Component\DependencyInjection\Reference;
12 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
13
21 class OutputVisitorPass implements CompilerPassInterface
22 {
23 public function process(ContainerBuilder $container)
24 {
25 if (!$container->hasDefinition('ezpublish_rest.output.visitor.dispatcher')) {
26 return;
27 }
28
29 $definition = $container->getDefinition('ezpublish_rest.output.visitor.dispatcher');
30
31 $visitors = [];
32
33 foreach ($container->findTaggedServiceIds('ezpublish_rest.output.visitor') as $id => $attributes) {
34 foreach ($attributes as $attribute) {
35 $priority = isset($attribute['priority']) ? $attribute['priority'] : 0;
36
37 if (!isset($attribute['regexps'])) {
38 throw new \LogicException('ezpublish_rest.output.visitor service tag needs a "regexps" attribute to identify the Accept header. None given.');
39 }
40
41 if (is_array($attribute['regexps'])) {
42 $regexps = $attribute['regexps'];
43 } elseif (is_string($attribute['regexps'])) {
44 try {
45 $regexps = $container->getParameter($attribute['regexps']);
46 } catch (InvalidArgumentException $e) {
47 throw new \LogicException("The regexps attribute of the ezpublish_rest.output.visitor service tag can be a string matching a container parameter name. No parameter {$attribute['regexps']} could be found.");
48 }
49 } else {
50 throw new \LogicException('ezpublish_rest.output.visitor service tag needs a "regexps" attribute, either as an array or a string. Invalid value.');
51 }
52
53 $visitors[$priority][] = [
54 'regexps' => $regexps,
55 'reference' => new Reference($id),
56 ];
57 }
58 }
59
60 // sort by priority and flatten
61 krsort($visitors);
62 $visitors = array_merge(...$visitors);
63
64 foreach ($visitors as $visitor) {
65 foreach ($visitor['regexps'] as $regexp) {
66 $definition->addMethodCall(
67 'addVisitor', [
68 $regexp,
69 $visitor['reference'],
70 ]
71 );
72 }
73 }
74 }
75 }
eZ\Bundle\EzPublishRestBundle\DependencyInjection\Compiler\OutputVisitorPass
Compiler pass for the ezpublish_rest.output.visitor tag.
Definition: OutputVisitorPass.php:22
eZ\Bundle\EzPublishRestBundle\DependencyInjection\Compiler\OutputVisitorPass\process
process(ContainerBuilder $container)
Definition: OutputVisitorPass.php:23
eZ\Bundle\EzPublishRestBundle\DependencyInjection\Compiler
Definition: FieldTypeProcessorPass.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.