Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Settings] Do not inject container to ParameterTransformerListener #5991

Merged
merged 1 commit into from
Sep 6, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sylius\Bundle\SettingsBundle\Schema\SchemaInterface;
use Sylius\Bundle\SettingsBundle\Schema\SettingsBuilder;
use Sylius\Bundle\SettingsBundle\Transformer\ParameterTransformerInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -26,22 +27,21 @@
final class ParameterTransformerListener
{
/**
* @var ContainerInterface
* @var ServiceRegistryInterface
*/
private $container;
private $settingsSchemaRegistry;

/**
* @var array
*/
private $parametersMap = [];

/**
* @param ContainerInterface $container
* @param ServiceRegistryInterface $settingsSchemaRegistry
*/
public function __construct(ContainerInterface $container)
public function __construct(ServiceRegistryInterface $settingsSchemaRegistry)
{
// FIXME: Do not inject the container!
$this->container = $container;
$this->settingsSchemaRegistry = $settingsSchemaRegistry;
}

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ public function postFlush()
* @param SettingsInterface $settings
* @param EntityManager $entityManager
*/
protected function transform(SettingsInterface $settings, EntityManager $entityManager)
private function transform(SettingsInterface $settings, EntityManager $entityManager)
{
// store old parameters, so we can revert to it after flush
$this->parametersMap[] = [
Expand All @@ -114,7 +114,7 @@ protected function transform(SettingsInterface $settings, EntityManager $entityM
/**
* @param SettingsInterface $settings
*/
protected function reverseTransform(SettingsInterface $settings)
private function reverseTransform(SettingsInterface $settings)
{
$transformers = $this->getTransformers($settings);
foreach ($settings->getParameters() as $name => $value) {
Expand All @@ -129,12 +129,10 @@ protected function reverseTransform(SettingsInterface $settings)
*
* @return ParameterTransformerInterface[]
*/
protected function getTransformers(SettingsInterface $settings)
private function getTransformers(SettingsInterface $settings)
{
$registry = $this->container->get('sylius.registry.settings_schema');

/** @var SchemaInterface $schema */
$schema = $registry->get($settings->getSchemaAlias());
$schema = $this->settingsSchemaRegistry->get($settings->getSchemaAlias());

$settingsBuilder = new SettingsBuilder();
$schema->buildSettings($settingsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</service>

<service id="sylius.settings.doctrine.transform_settings_listener" class="%sylius.settings.doctrine.parameter_transformer_listener.class%">
<argument type="service" id="service_container"/>
<argument type="service" id="sylius.registry.settings_schema"/>
<tag name="doctrine.event_listener" event="onFlush"/>
<tag name="doctrine.event_listener" event="postFlush"/>
<tag name="doctrine.event_listener" event="postLoad"/>
Expand Down