<?php

namespace Webkul\DamBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
 */
class WebkulDamExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('event_listener.yml');
        $loader->load('services.yml');
        $loader->load('array_converters.yml');
        $loader->load('attribute_types.yml');
        $loader->load('comparators.yml');
        $loader->load('updaters.yml');
        $loader->load('providers.yml');
        $loader->load('data_sources.yml');
        $loader->load('repositories.yml');

        $loader->load('jobs.yml');
        $loader->load('steps.yml');
        $loader->load('readers.yml');
        $loader->load('writers.yml');
        $loader->load('processors.yml');
        $loader->load('job_parameters.yml');
        $loader->load('form_entry.yml');
        $loader->load('datagrid/asset_attribute.yml');
        $loader->load('factories.yml');
        $loader->load('serializers_standard.yml');
        $loader->load('savers.yml');
        $loader->load('controllers.yml');
        $loader->load('context.yml');
        $loader->load('remover.yml');
        $loader->load('mass_actions.yml');
        
        if (class_exists('Akeneo\Platform\CommunityVersion')) {
            $versionClass = new \Akeneo\Platform\CommunityVersion();
        } elseif (class_exists('Pim\Bundle\CatalogBundle\Version')) {
            $versionClass = new \Pim\Bundle\CatalogBundle\Version();
        }
        $version = $versionClass::VERSION;
        
        if ($version > '3.0') {
            $versionDirectoryPrefix = '3.0/';
            $loader->load('3.0/servicenames.yml');
            $loader->load('3.0/controllers.yml');
            $loader->load('3.0/context.yml');
        } else {
            $loader->load('2.x/servicenames.yml');
        }

        if ($version > '4.0') {
            $loader->load('4.0/factories.yml');
        }


    }
}
