diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index bb3856fc60..415a2e9202 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -201,6 +201,9 @@ class container_builder // Easy collections through tags $this->container->addCompilerPass(new pass\collection_pass()); + // Mark all services public + $this->container->addCompilerPass(new pass\markpublic_pass()); + // Event listeners "phpBB style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); @@ -217,9 +220,6 @@ class container_builder $this->inject_custom_parameters(); - // Mark all services public - $this->container->addCompilerPass(new pass\markpublic_pass()); - if ($this->compile_container) { $this->container->compile(); diff --git a/phpBB/phpbb/di/pass/markpublic_pass.php b/phpBB/phpbb/di/pass/markpublic_pass.php index 7e5a8ae8ac..a24ba32a68 100644 --- a/phpBB/phpbb/di/pass/markpublic_pass.php +++ b/phpBB/phpbb/di/pass/markpublic_pass.php @@ -23,15 +23,24 @@ class markpublic_pass implements CompilerPassInterface { /** * Modify the container before it is passed to the rest of the code + * Mark services as public by default unless they were explicitly marked as private * * @param ContainerBuilder $container ContainerBuilder object * @return null */ public function process(ContainerBuilder $container) { - foreach ($container->getDefinitions() as $definition) + $service_definitions = $container->getDefinitions(); + foreach ($service_definitions as $definition) { - if ($definition->isPrivate()) + $changes = $definition->getChanges(); + + /* Check if service definition contains explicit 'public' key (changed default state) + * If it does and the service is private, then service was explicitly marked as private + * Don't mark it as public then + */ + $definition_override_public = isset($changes['public']) && $changes['public']; + if (!$definition_override_public && $definition->isPrivate()) { $definition->setPublic(true); } @@ -39,7 +48,10 @@ class markpublic_pass implements CompilerPassInterface foreach ($container->getAliases() as $alias) { - if ($alias->isPrivate()) + $aliased_service_id = $alias->__toString(); + + // Only mark alias as public if original service is public too + if ($service_definitions[$aliased_service_id]->isPublic() && $alias->isPrivate()) { $alias->setPublic(true); }