<?xml version="1.0" encoding="UTF-8"?>

<!--

 This file is part of the Sylius package.

 (c) Sylius Sp. z o.o.

 For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.

-->

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <parameters>
        <parameter key="sylius.form.type.locale.validation_groups" type="collection">
            <parameter>sylius</parameter>
        </parameter>
    </parameters>

    <services>
        <defaults public="true" />

        <service id="sylius.form.type.locale" class="Sylius\Bundle\LocaleBundle\Form\Type\LocaleType">
            <argument>%sylius.model.locale.class%</argument>
            <argument>%sylius.form.type.locale.validation_groups%</argument>
            <tag name="form.type" />
        </service>

        <service id="sylius.form.data_transformer.locale_to_code" class="Sylius\Bundle\LocaleBundle\Form\DataTransformer\LocaleToCodeTransformer">
            <argument type="service" id="sylius.locale_collection_provider" />
        </service>

        <service id="sylius.form.type.locale_choice" class="Sylius\Bundle\LocaleBundle\Form\Type\LocaleChoiceType">
            <argument type="service" id="sylius.repository.locale" />
            <tag name="form.type" />
        </service>

        <service id="sylius.context.locale" class="Sylius\Component\Locale\Context\ImmutableLocaleContext">
            <argument>%sylius_locale.locale%</argument>
        </service>
        <service id="Sylius\Component\Locale\Context\LocaleContextInterface" alias="sylius.context.locale" />

        <service id="sylius.context.locale.composite" class="Sylius\Component\Locale\Context\CompositeLocaleContext" decorates="sylius.context.locale" decoration-priority="256" public="false" />

        <service id="Sylius\Bundle\LocaleBundle\Context\RequestHeaderBasedLocaleContext">
            <argument type="service" id="request_stack" />
            <argument type="service" id="sylius.locale_provider" />
            <tag name="sylius.context.locale" priority="32" />
        </service>

        <service id="sylius.locale_collection_provider" class="Sylius\Component\Locale\Provider\LocaleCollectionProvider">
            <argument type="service" id="sylius.repository.locale" />
        </service>

        <service id="sylius.locale_collection_provider.cached" class="Sylius\Component\Locale\Provider\CachedLocaleCollectionProvider" decorates="sylius.locale_collection_provider">
            <argument type="service" id=".inner" />
            <argument type="service" id="cache.app" />
        </service>

        <service id="sylius.locale_provider" class="Sylius\Component\Locale\Provider\LocaleProvider">
            <argument type="service" id="sylius.locale_collection_provider" />
            <argument>%sylius_locale.locale%</argument>
        </service>
        <service id="Sylius\Component\Locale\Provider\LocaleProviderInterface" alias="sylius.locale_provider" />

        <service id="sylius.locale_converter" class="Sylius\Component\Locale\Converter\LocaleConverter" />
        <service id="Sylius\Component\Locale\Converter\LocaleConverterInterface" alias="sylius.locale_converter" />

        <service id="sylius.listener.request_locale_setter" class="Sylius\Bundle\LocaleBundle\Listener\RequestLocaleSetter">
            <argument type="service" id="sylius.context.locale" />
            <argument type="service" id="sylius.locale_provider" />
            <tag name="kernel.event_listener" event="kernel.request" priority="4" />
        </service>

        <service id="sylius.templating.helper.locale" class="Sylius\Bundle\LocaleBundle\Templating\Helper\LocaleHelper">
            <argument type="service" id="sylius.locale_converter" />
            <argument type="service" id="sylius.context.locale" />
            <tag name="templating.helper" alias="sylius_locale" />
        </service>

        <service id="sylius.twig.extension.locale" class="Sylius\Bundle\LocaleBundle\Twig\LocaleExtension" public="false">
            <argument type="service" id="sylius.templating.helper.locale" />
            <tag name="twig.extension" />
        </service>

        <service id="Sylius\Bundle\LocaleBundle\Checker\LocaleUsageCheckerInterface" class="Sylius\Bundle\LocaleBundle\Checker\LocaleUsageChecker">
            <argument type="service" id="sylius.repository.locale" />
            <argument type="service" id="sylius.resource_registry" />
            <argument type="service" id="doctrine.orm.entity_manager" />
        </service>

        <service id="Sylius\Bundle\LocaleBundle\Doctrine\EventListener\LocaleModificationListener">
            <argument type="service" id="cache.app" />
            <tag name="doctrine.orm.entity_listener" event="postPersist" entity="Sylius\Component\Locale\Model\Locale" method="invalidateCachedLocales" />
            <tag name="doctrine.orm.entity_listener" event="postUpdate" entity="Sylius\Component\Locale\Model\Locale" method="invalidateCachedLocales" />
            <tag name="doctrine.orm.entity_listener" event="postRemove" entity="Sylius\Component\Locale\Model\Locale" method="invalidateCachedLocales" />
        </service>
    </services>
</container>
