Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions DependencyInjection/MarkupNeedleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;

/**
* This is the class that loads and manages your bundle configuration
Expand Down Expand Up @@ -42,6 +44,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->loadSuggestHandler($config, $container);
$this->loadTerms($config, $container);
$this->loadTermsField($config, $container);
$this->markSharedServices($container);
}

/**
Expand Down Expand Up @@ -222,4 +225,35 @@ private function loadTermsField(array $config, ContainerBuilder $container)
{
$container->setAlias('markup_needle.terms_field', $config['terms_field_provider']);
}

private function markSharedServices(ContainerBuilder $container)
{
$sharedServiceIds = [
'markup_needle.exporter.closure.prototype',
'markup_needle.interceptor.prototype',
];
$sharedServiceDefinitions = array_map(
function ($id) use ($container) {
return $container->getDefinition($id);
},
$sharedServiceIds
);

//if before symfony 2.8, service is set to have "scope" of "prototype", rather than setting as shared
if (version_compare(Kernel::VERSION, '2.8.0', '>=')) {
array_map(
function (Definition $definition) {
$definition->setShared(true);
},
$sharedServiceDefinitions
);
} else {
array_map(
function (Definition $definition) {
$definition->setScope(ContainerInterface::SCOPE_PROTOTYPE, false);
},
$sharedServiceDefinitions
);
}
}
}
2 changes: 0 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ services:
- %markup_needle.allow_null_values_in_update_fields%
markup_needle.exporter.closure.prototype:
parent: markup_needle.exporter.closure
scope: prototype
markup_needle.exporter.closure.generator:
parent: markup_needle.service_closure
arguments:
Expand Down Expand Up @@ -99,7 +98,6 @@ services:
class: Markup\NeedleBundle\Intercept\Interceptor
arguments:
- '@event_dispatcher'
scope: prototype
markup_needle.interceptor.closure:
parent: markup_needle.service_closure
arguments:
Expand Down