mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-21 08:00:46 +01:00
[ticket/16649] Correctly handle marking services as private
PHPBB3-16649
This commit is contained in:
parent
497d2965f9
commit
929acfb64c
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user