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

ExternalStorageRegistryPass.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Base\Container\Compiler\Storage;
8
9 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10 use Symfony\Component\DependencyInjection\ContainerBuilder;
11 use Symfony\Component\DependencyInjection\Reference;
12 use LogicException;
13
17 class ExternalStorageRegistryPass implements CompilerPassInterface
18 {
24 public function process(ContainerBuilder $container)
25 {
26 if (!$container->hasDefinition('ezpublish.persistence.external_storage_registry.factory')) {
27 return;
28 }
29
30 $externalStorageRegistryFactoryDefinition = $container->getDefinition(
31 'ezpublish.persistence.external_storage_registry.factory'
32 );
33
34 // Gateways for external storage handlers.
35 // Alias attribute is the corresponding field type string.
36 $externalStorageGateways = [];
37 // Referencing the services by alias (field type string)
38 foreach ($container->findTaggedServiceIds('ezpublish.fieldType.externalStorageHandler.gateway') as $id => $attributes) {
39 foreach ($attributes as $attribute) {
40 if (!isset($attribute['alias'])) {
41 throw new LogicException('ezpublish.fieldType.externalStorageHandler.gateway service tag needs an "alias" attribute to identify the field type. None given.');
42 }
43
44 if (!isset($attribute['identifier'])) {
45 throw new LogicException('ezpublish.fieldType.externalStorageHandler.gateway service tag needs an "identifier" attribute to identify the gateway. None given.');
46 }
47
48 $externalStorageGateways[$attribute['alias']] = [
49 'id' => $id,
50 'identifier' => $attribute['identifier'],
51 ];
52 }
53 }
54
55 // External storage handlers for field types that need them.
56 // Alias attribute is the field type string.
57 foreach ($container->findTaggedServiceIds('ezpublish.fieldType.externalStorageHandler') as $id => $attributes) {
58 foreach ($attributes as $attribute) {
59 if (!isset($attribute['alias'])) {
60 throw new LogicException('ezpublish.fieldType.externalStorageHandler service tag needs an "alias" attribute to identify the field type. None given.');
61 }
62
63 // If the storage handler is gateway based, then we need to add a corresponding gateway to it.
64 // Will throw a LogicException if no gateway is defined for this field type.
65 $storageHandlerDef = $container->findDefinition($id);
66 $storageHandlerClass = $storageHandlerDef->getClass();
67 if (preg_match('/^%([^%\s]+)%$/', $storageHandlerClass, $match)) {
68 $storageHandlerClass = $container->getParameter($match[1]);
69 }
70
71 if (
72 is_subclass_of(
73 $storageHandlerClass,
74 'eZ\\Publish\\Core\\FieldType\\GatewayBasedStorage'
75 )
76 ) {
77 if (!isset($externalStorageGateways[$attribute['alias']])) {
78 throw new LogicException(
79 "External storage handler '$id' for field type {$attribute['alias']} needs a storage gateway but none was given.
80 Consider defining a storage gateway as a service for this field type and add the 'ezpublish.fieldType.externalStorageHandler.gateway tag'"
81 );
82 }
83
84 $storageHandlerDef->addMethodCall(
85 'addGateway',
86 [
87 $externalStorageGateways[$attribute['alias']]['identifier'],
88 new Reference($externalStorageGateways[$attribute['alias']]['id']),
89 ]
90 );
91 }
92
93 $externalStorageRegistryFactoryDefinition->addMethodCall(
94 'registerExternalStorageHandler',
95 [
96 $id,
97 $attribute['alias'],
98 ]
99 );
100 }
101 }
102 }
103 }
eZ\Publish\Core\Base\Container\Compiler\Storage\ExternalStorageRegistryPass
This compiler pass will register eZ Publish external storage handlers and gateways.
Definition: ExternalStorageRegistryPass.php:18
eZ\Publish\Core\Base\Container\Compiler\Storage\ExternalStorageRegistryPass\process
process(ContainerBuilder $container)
Definition: ExternalStorageRegistryPass.php:24
eZ\Publish\Core\Base\Container\Compiler\Storage
Definition: ExternalStorageRegistryPass.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.