mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 20:38:52 +00:00
[ticket/16649] Correctly handle marking services as private
PHPBB3-16649
This commit is contained in:
parent
497d2965f9
commit
929acfb64c
2 changed files with 18 additions and 6 deletions
|
@ -201,6 +201,9 @@ class container_builder
|
||||||
// Easy collections through tags
|
// Easy collections through tags
|
||||||
$this->container->addCompilerPass(new pass\collection_pass());
|
$this->container->addCompilerPass(new pass\collection_pass());
|
||||||
|
|
||||||
|
// Mark all services public
|
||||||
|
$this->container->addCompilerPass(new pass\markpublic_pass());
|
||||||
|
|
||||||
// Event listeners "phpBB style"
|
// Event listeners "phpBB style"
|
||||||
$this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener'));
|
$this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener'));
|
||||||
|
|
||||||
|
@ -217,9 +220,6 @@ class container_builder
|
||||||
|
|
||||||
$this->inject_custom_parameters();
|
$this->inject_custom_parameters();
|
||||||
|
|
||||||
// Mark all services public
|
|
||||||
$this->container->addCompilerPass(new pass\markpublic_pass());
|
|
||||||
|
|
||||||
if ($this->compile_container)
|
if ($this->compile_container)
|
||||||
{
|
{
|
||||||
$this->container->compile();
|
$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
|
* 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
|
* @param ContainerBuilder $container ContainerBuilder object
|
||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
public function process(ContainerBuilder $container)
|
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);
|
$definition->setPublic(true);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +48,10 @@ class markpublic_pass implements CompilerPassInterface
|
||||||
|
|
||||||
foreach ($container->getAliases() as $alias)
|
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);
|
$alias->setPublic(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue