Skip to content

Commit 76c4217

Browse files
[FrameworkBundle] Fix Di config to allow for more private services
1 parent aad90fa commit 76c4217

File tree

13 files changed

+65
-55
lines changed

13 files changed

+65
-55
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolClearerPass.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,16 @@ final class CachePoolClearerPass implements CompilerPassInterface
2727
public function process(ContainerBuilder $container)
2828
{
2929
$container->getParameterBag()->remove('cache.prefix.seed');
30-
$poolsByClearer = array();
31-
$pools = array();
3230

33-
foreach ($container->findTaggedServiceIds('cache.pool') as $id => $attributes) {
34-
$pools[$id] = new Reference($id);
35-
foreach (array_reverse($attributes) as $attr) {
36-
if (isset($attr['clearer'])) {
37-
$poolsByClearer[$attr['clearer']][$id] = $pools[$id];
38-
}
39-
if (!empty($attr['unlazy'])) {
40-
$container->getDefinition($id)->setLazy(false);
41-
}
42-
if (array_key_exists('clearer', $attr) || array_key_exists('unlazy', $attr)) {
43-
break;
31+
foreach ($container->findTaggedServiceIds('cache.pool.clearer') as $id => $attr) {
32+
$clearer = $container->getDefinition($id);
33+
$pools = array();
34+
foreach ($clearer->getArgument(0) as $id => $ref) {
35+
if ($container->hasDefinition($id)) {
36+
$pools[$id] = new Reference($id);
4437
}
4538
}
46-
}
47-
48-
$container->getDefinition('cache.global_clearer')->addArgument($pools);
49-
50-
foreach ($poolsByClearer as $clearer => $pools) {
51-
$clearer = $container->getDefinition($clearer);
52-
$clearer->addArgument($pools);
39+
$clearer->replaceArgument(0, $pools);
5340
}
5441

5542
if (!$container->has('cache.annotations')) {

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function process(ContainerBuilder $container)
3737
}
3838
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
3939

40+
$pools = array();
41+
$clearers = array();
4042
$attributes = array(
4143
'provider',
4244
'namespace',
@@ -47,10 +49,8 @@ public function process(ContainerBuilder $container)
4749
if ($pool->isAbstract()) {
4850
continue;
4951
}
50-
$isLazy = $pool->isLazy();
5152
while ($adapter instanceof ChildDefinition) {
5253
$adapter = $container->findDefinition($adapter->getParent());
53-
$isLazy = $isLazy || $adapter->isLazy();
5454
if ($t = $adapter->getTag('cache.pool')) {
5555
$tags[0] += $t[0];
5656
}
@@ -82,17 +82,29 @@ public function process(ContainerBuilder $container)
8282
throw new InvalidArgumentException(sprintf('Invalid "cache.pool" tag for service "%s": accepted attributes are "clearer", "provider", "namespace" and "default_lifetime", found "%s".', $id, implode('", "', array_keys($tags[0]))));
8383
}
8484

85-
$attr = array();
8685
if (null !== $clearer) {
87-
$attr['clearer'] = $clearer;
86+
$clearers[$clearer][$id] = new Reference($id, $container::IGNORE_ON_UNINITIALIZED_REFERENCE);
8887
}
89-
if (!$isLazy) {
90-
$pool->setLazy(true);
91-
$attr['unlazy'] = true;
92-
}
93-
if ($attr) {
94-
$pool->addTag('cache.pool', $attr);
88+
89+
$pools[$id] = new Reference($id, $container::IGNORE_ON_UNINITIALIZED_REFERENCE);
90+
}
91+
92+
$clearer = 'cache.global_clearer';
93+
while ($container->hasAlias($clearer)) {
94+
$clearer = (string) $container->getAlias($clearer);
95+
}
96+
if ($container->hasDefinition($clearer)) {
97+
$clearers['cache.global_clearer'] = $pools;
98+
}
99+
100+
foreach ($clearers as $id => $pools) {
101+
$clearer = $container->getDefinition($id);
102+
if ($clearer instanceof ChilDefinition) {
103+
$clearer->replaceArgument(0, $pools);
104+
} else {
105+
$clearer->setArgument(0, $pools);
95106
}
107+
$clearer->addTag('cache.pool.clearer');
96108
}
97109
}
98110

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TemplatingPass.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Alias;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\Reference;
1819
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
1920

2021
class TemplatingPass implements CompilerPassInterface
@@ -31,16 +32,22 @@ public function process(ContainerBuilder $container)
3132
}
3233

3334
if ($container->hasDefinition('templating.engine.php')) {
35+
$refs = array();
3436
$helpers = array();
3537
foreach ($container->findTaggedServiceIds('templating.helper', true) as $id => $attributes) {
3638
if (isset($attributes[0]['alias'])) {
3739
$helpers[$attributes[0]['alias']] = $id;
40+
$refs[$id] = new Reference($id);
3841
}
3942
}
4043

4144
if (count($helpers) > 0) {
4245
$definition = $container->getDefinition('templating.engine.php');
4346
$definition->addMethodCall('setHelpers', array($helpers));
47+
48+
if ($container->hasDefinition('templating.engine.php.helpers_locator')) {
49+
$container->getDefinition('templating.engine.php.helpers_locator')->replaceArgument(0, $refs);
50+
}
4451
}
4552
}
4653
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class UnusedTagsPass implements CompilerPassInterface
2323
{
2424
private $whitelist = array(
25+
'cache.pool.clearer',
2526
'console.command',
2627
'container.service_locator',
2728
'container.service_subscriber',

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,15 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
597597
}
598598

599599
// Create Workflow
600+
$workflowId = sprintf('%s.%s', $type, $name);
600601
$workflowDefinition = new ChildDefinition(sprintf('%s.abstract', $type));
601-
$workflowDefinition->replaceArgument(0, $definitionDefinition);
602+
$workflowDefinition->replaceArgument(0, new Reference(sprintf('%s.definition', $workflowId)));
602603
if (isset($markingStoreDefinition)) {
603604
$workflowDefinition->replaceArgument(1, $markingStoreDefinition);
604605
}
605606
$workflowDefinition->replaceArgument(3, $name);
606607

607608
// Store to container
608-
$workflowId = sprintf('%s.%s', $type, $name);
609609
$container->setDefinition($workflowId, $workflowDefinition);
610610
$container->setDefinition(sprintf('%s.definition', $workflowId), $definitionDefinition);
611611

@@ -680,7 +680,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
680680

681681
if (class_exists(Stopwatch::class)) {
682682
$container->register('debug.stopwatch', Stopwatch::class)->addArgument(true);
683-
$container->setAlias(Stopwatch::class, 'debug.stopwatch');
683+
$container->setAlias(Stopwatch::class, new Alias('debug.stopwatch', false));
684684
}
685685

686686
$debug = $container->getParameter('kernel.debug');

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function build(ContainerBuilder $container)
106106
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
107107
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
108108
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
109-
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
109+
$container->addCompilerPass(new FragmentRendererPass());
110110
$this->addCompilerPassIfExists($container, SerializerPass::class);
111111
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
112112
$container->addCompilerPass(new DataCollectorTranslatorPass());

src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<service id="debug.templating.engine.php" class="Symfony\Bundle\FrameworkBundle\Templating\TimedPhpEngine">
1111
<argument type="service" id="templating.name_parser" />
12-
<argument type="service" id="service_container" />
12+
<argument type="service" id="templating.engine.php.helpers_locator" />
1313
<argument type="service" id="templating.loader" />
1414
<argument type="service" id="debug.stopwatch" />
1515
<argument type="service" id="templating.globals" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010
<service id="templating.engine.php" class="Symfony\Bundle\FrameworkBundle\Templating\PhpEngine">
1111
<argument type="service" id="templating.name_parser" />
12-
<argument type="service" id="service_container" />
12+
<argument type="service" id="templating.engine.php.helpers_locator" />
1313
<argument type="service" id="templating.loader" />
1414
<argument type="service" id="templating.globals" />
1515
<call method="setCharset"><argument>%kernel.charset%</argument></call>
1616
</service>
1717

18+
<service id="templating.engine.php.helpers_locator">
19+
<tag name="container.service_locator" />
20+
<argument type="collection" />
21+
</service>
22+
1823
<service id="templating.helper.slots" class="Symfony\Component\Templating\Helper\SlotsHelper" public="true">
1924
<tag name="templating.helper" alias="slots" />
2025
</service>

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function block(FormView $view, $blockName, array $variables = array())
226226
* Check the token in your action using the same CSRF token id.
227227
*
228228
* <code>
229-
* $csrfProvider = $this->get('security.csrf.token_generator');
229+
* // $csrfProvider being an instance of Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface
230230
* if (!$csrfProvider->isCsrfTokenValid('rm_user_'.$user->getId(), $token)) {
231231
* throw new \RuntimeException('CSRF attack detected.');
232232
* }

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ class SubRequestController implements ContainerAwareInterface
2121
{
2222
use ContainerAwareTrait;
2323

24-
public function indexAction()
24+
public function indexAction($handler)
2525
{
26-
$handler = $this->container->get('fragment.handler');
27-
2826
$errorUrl = $this->generateUrl('subrequest_fragment_error', array('_locale' => 'fr', '_format' => 'json'));
2927
$altUrl = $this->generateUrl('subrequest_fragment', array('_locale' => 'fr', '_format' => 'json'));
3028

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy