Skip to content

Commit 21590e7

Browse files
authored
support all versions of symfony re shared service declarations (#3)
1 parent de25194 commit 21590e7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

DependencyInjection/MarkupAddressingExtension.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\DependencyInjection\ContainerInterface;
78
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
89
use Symfony\Component\DependencyInjection\Loader;
10+
use Symfony\Component\HttpKernel\Kernel;
911

1012
/**
1113
* This is the class that loads and manages your bundle configuration
@@ -28,6 +30,7 @@ public function load(array $configs, ContainerBuilder $container)
2830
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
2931
$loader->load('services.yml');
3032

33+
$this->setSharedServices($container);
3134
$this->loadCountryPostalCodeOverrides($config, $container);
3235
}
3336

@@ -61,4 +64,18 @@ private function loadRequireStrictRegions(array $config, ContainerBuilder $conta
6164
{
6265
$container->setParameter('markup_addressing.require_strict_regions', $config['require_strict_regions']);
6366
}
67+
68+
private function setSharedServices(ContainerBuilder $container)
69+
{
70+
$sharedServiceIds = ['markup_addressing.twig.internal'];
71+
$isLegacy = version_compare(Kernel::VERSION, '2.8', '<');
72+
foreach ($sharedServiceIds as $sharedServiceId) {
73+
$definition = $container->getDefinition($sharedServiceId);
74+
if (!$isLegacy) {
75+
$definition->setShared(true);
76+
} else {
77+
$definition->setScope(ContainerInterface::SCOPE_PROTOTYPE, false);
78+
}
79+
}
80+
}
6481
}

Resources/config/services.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ services:
6464
- []
6565
calls:
6666
- [ addExtension, [ '@markup_addressing.country_name.extension' ] ]
67-
scope: prototype
6867
markup_addressing.twig.provider:
6968
class: 'Markup\Addressing\Provider\KeyedEnvironmentServiceProvider'
7069
arguments:

0 commit comments

Comments
 (0)