Skip to content

Commit 2775ca4

Browse files
committed
bug #1840 make the view handler alias public (xabbuh)
This PR was merged into the 2.3-dev branch. Discussion ---------- make the view handler alias public The alias will be fetched from the container when using the built-in FOSRestController class. Thus, we must ensure that it can still be located when using Symfony 4.0 or higher. Commits ------- 14d9c48 make the view handler alias public
2 parents f512797 + 14d9c48 commit 2775ca4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

DependencyInjection/FOSRestExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\RestBundle\DependencyInjection;
1313

1414
use Symfony\Component\Config\FileLocator;
15+
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\ChildDefinition;
1617
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -68,7 +69,11 @@ public function load(array $configs, ContainerBuilder $container)
6869
}
6970

7071
if (null !== $service) {
71-
$container->setAlias('fos_rest.'.$key, $service);
72+
if ('view_handler' === $key) {
73+
$container->setAlias('fos_rest.'.$key, new Alias($service, true));
74+
} else {
75+
$container->setAlias('fos_rest.'.$key, $service);
76+
}
7277
}
7378
}
7479

Tests/DependencyInjection/FOSRestExtensionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use FOS\RestBundle\DependencyInjection\FOSRestExtension;
1515
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\DependencyInjection\Alias;
1617
use Symfony\Component\DependencyInjection\ChildDefinition;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\DependencyInjection\Definition;
@@ -238,6 +239,14 @@ public function testLoadServicesWithDefaults()
238239
$this->extension->load([], $this->container);
239240

240241
$this->assertAlias('fos_rest.view_handler.default', 'fos_rest.view_handler');
242+
243+
$viewHandlerAlias = $this->container->getAlias('fos_rest.view_handler');
244+
245+
$this->assertTrue($viewHandlerAlias->isPublic());
246+
247+
if (method_exists(Alias::class, 'isPrivate')) {
248+
$this->assertFalse($viewHandlerAlias->isPrivate());
249+
}
241250
}
242251

243252
public function testDisableViewResponseListener()

0 commit comments

Comments
 (0)