|
11 | 11 |
|
12 | 12 | namespace App; |
13 | 13 |
|
| 14 | +use Pimcore\Config\BundleConfigLocator; |
14 | 15 | use Pimcore\Kernel as BaseKernel; |
15 | 16 | use Symfony\Component\Config\Loader\LoaderInterface; |
16 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
17 | | -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
18 | 18 |
|
19 | 19 | class Kernel extends BaseKernel |
20 | 20 | { |
21 | 21 | /** |
22 | | - * Override configureContainer to prevent MicroKernelTrait from auto-loading |
23 | | - * config/services.yaml. In this CI setup, the bundle IS the project root, |
24 | | - * so config/services.yaml belongs to the bundle and is already loaded by the |
25 | | - * bundle extension's load() method. Loading it again here would overwrite |
| 22 | + * Override registerContainerConfiguration() to prevent MicroKernelTrait from |
| 23 | + * auto-loading config/services.yaml. In this CI setup, the bundle IS the project |
| 24 | + * root, so config/services.yaml belongs to the bundle and is already loaded by |
| 25 | + * the bundle extension's load() method. Loading it again here would overwrite |
26 | 26 | * the programmatic argument assignments made by the extension |
27 | 27 | * (e.g., $clientType, $queueSettings on SearchIndexConfigServiceInterface |
28 | 28 | * and DispatchQueueMessagesHandler). |
29 | 29 | * |
30 | | - * We still load packages and environment-specific service files |
31 | | - * (services_test.yaml) which provide test-only service overrides. |
| 30 | + * Previously this was achieved by overriding the protected configureContainer() |
| 31 | + * extension point exposed by Pimcore\Kernel via a MicroKernelTrait alias. |
| 32 | + * That extension point relies on a private method of Symfony's MicroKernelTrait |
| 33 | + * whose signature is not part of Symfony's public API and changes between |
| 34 | + * minor versions. Overriding the public registerContainerConfiguration() method |
| 35 | + * instead avoids this coupling and remains stable across Symfony 6.4, 7.x and |
| 36 | + * future versions. |
| 37 | + * |
| 38 | + * This implementation mirrors Pimcore\Kernel::registerContainerConfiguration() |
| 39 | + * (BundleConfigLocator + packages + env services) but intentionally skips the |
| 40 | + * MicroKernelTrait services.yaml auto-load and the dynamic Pimcore config |
| 41 | + * directories (image_thumbnails, document_types, etc.) which are not used in |
| 42 | + * this bundle's CI. |
32 | 43 | */ |
33 | | - protected function configureContainer(ContainerConfigurator $container, LoaderInterface $loader, ContainerBuilder $builder): void |
| 44 | + public function registerContainerConfiguration(LoaderInterface $loader): void |
34 | 45 | { |
35 | | - $configDir = $this->getProjectDir() . '/{config}'; |
| 46 | + // Register the synthetic "kernel" service and configure the framework |
| 47 | + // router to load its routes from kernel::loadRoutes(). This is normally |
| 48 | + // done by MicroKernelTrait::registerContainerConfiguration(); we |
| 49 | + // replicate the relevant bits here so the kernel may be depended on via |
| 50 | + // DI and so framework.router.resource is configured (otherwise the |
| 51 | + // FrameworkBundle config validation fails with "The child config |
| 52 | + // 'resource' under 'framework.router' must be configured."). |
| 53 | + $loader->load(function (ContainerBuilder $container): void { |
| 54 | + $container->loadFromExtension('framework', [ |
| 55 | + 'router' => [ |
| 56 | + 'resource' => 'kernel::loadRoutes', |
| 57 | + 'type' => 'service', |
| 58 | + ], |
| 59 | + ]); |
| 60 | + |
| 61 | + if (!$container->hasDefinition('kernel')) { |
| 62 | + $container->register('kernel', static::class) |
| 63 | + ->addTag('controller.service_arguments') |
| 64 | + ->setAutoconfigured(true) |
| 65 | + ->setSynthetic(true) |
| 66 | + ->setPublic(true); |
| 67 | + } |
| 68 | + |
| 69 | + $container->getDefinition('kernel')->addTag('routing.route_loader'); |
| 70 | + }); |
| 71 | + |
| 72 | + // Load bundle-provided config files from <bundle>/Resources/config/pimcore |
| 73 | + // or <bundle>/config/pimcore (e.g. config.yaml -> messenger.yaml). |
| 74 | + // This mirrors Pimcore\Kernel::registerContainerConfiguration(). |
| 75 | + $bundleConfigLocator = new BundleConfigLocator($this); |
| 76 | + foreach ($bundleConfigLocator->locate('config') as $bundleConfig) { |
| 77 | + $loader->load($bundleConfig); |
| 78 | + } |
| 79 | + |
| 80 | + $configDir = $this->getProjectDir() . '/config'; |
36 | 81 |
|
37 | | - $container->import($configDir . '/{packages}/*.{php,yaml}'); |
38 | | - $container->import($configDir . '/{packages}/' . $this->environment . '/*.{php,yaml}'); |
| 82 | + // Load packages (mirrors MicroKernelTrait's default configureContainer behavior). |
| 83 | + $loader->load($configDir . '/packages/*.{php,yaml}', 'glob'); |
| 84 | + $loader->load($configDir . '/packages/' . $this->environment . '/*.{php,yaml}', 'glob'); |
39 | 85 |
|
40 | 86 | // Skip loading config/services.yaml — it is the bundle's own service config |
41 | 87 | // and is already loaded by PimcoreGenericDataIndexExtension::load(). |
42 | 88 | // Only load the environment-specific services file (e.g., services_test.yaml). |
43 | | - $container->import($configDir . '/{services}_' . $this->environment . '.yaml'); |
| 89 | + $envServices = $configDir . '/services_' . $this->environment . '.yaml'; |
| 90 | + if (file_exists($envServices)) { |
| 91 | + $loader->load($envServices); |
| 92 | + } |
44 | 93 | } |
45 | 94 | } |
0 commit comments