<commit_before><?php

namespace Akeneo\Bundle\BatchBundle\DependencyInjection\Compiler;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\NodeInterface;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Yaml\Parser as YamlParser;

/**
 * Read the batch_jobs.yml file of the connectors to register the jobs
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/MIT MIT
 */
class RegisterJobsPass implements CompilerPassInterface
{
    /**
     * @var YamlParser
     */
    protected $yamlParser;

    /**
     * @var NodeInterface
     */
    protected $jobsConfig;

    /**
     * @param YamlParser $yamlParser
     */
    public function __construct($yamlParser = null)
    {
        $this->yamlParser = $yamlParser ?: new YamlParser();
    }

    /**
     * @param ContainerBuilder $container
     */
    public function process(ContainerBuilder $container)
    {
        $registry = $container->getDefinition('akeneo_batch.connectors');

        foreach ($container->getParameter('kernel.bundles') as $bundle) {
            $reflClass = new \ReflectionClass($bundle);
            if (false === $bundleDir = dirname($reflClass->getFileName())) {
                continue;
            }
            if (is_file($configFile = $bundleDir.'/Resources/config/batch_jobs.yml')) {
                $container->addResource(new FileResource($configFile));
                $this->registerJobs($registry, $configFile);
            }
        }
    }

    /**
     * @param Definition $definition
     * @param string     $configFile
     */
    protected function registerJobs(Definition $definition, $configFile)
    {
        $config = $this->processConfig(
            $this->yamlParser->parse(
                file_get_contents($configFile)
            )
        );

        foreach ($config['jobs'] as $alias => $job) {
            foreach ($job['steps'] as $step) {<commit_msg>PIM-5645: Split Akeneo Native connector<commit_after><?php

namespace Akeneo\Bundle\BatchBundle\DependencyInjection\Compiler;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\NodeInterface;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Parser as YamlParser;

/**
 * Read the batch_jobs.yml file or batch_jobs folder of the connectors to register the jobs
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2013 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/MIT MIT
 */
class RegisterJobsPass implements CompilerPassInterface
{
    /**
     * @var YamlParser
     */
    protected $yamlParser;

    /**
     * @var NodeInterface
     */
    protected $jobsConfig;

    /**
     * @param YamlParser $yamlParser
     */
    public function __construct($yamlParser = null)
    {
        $this->yamlParser = $yamlParser ?: new YamlParser();
    }

    /**
     * @param ContainerBuilder $container
     */
    public function process(ContainerBuilder $container)
    {
        $registry = $container->getDefinition('akeneo_batch.connectors');
        $configFileDir =
            DIRECTORY_SEPARATOR . 'Resources' .
            DIRECTORY_SEPARATOR . 'config' .
            DIRECTORY_SEPARATOR . 'batch_jobs';


        foreach ($container->getParameter('kernel.bundles') as $bundle) {
            $reflClass = new \ReflectionClass($bundle);
            if (false === $bundleDir = dirname($reflClass->getFileName())) {
                continue;
            }

            $configFiles = [];
            if (is_dir($configDir = $bundleDir . $configFileDir)) {
                $finder = Finder::create()->files()->in($configDir);
                foreach ($finder as $file) {
                    if (is_file($file->getPathname())) {
                        $configFiles[] = $file->getPathname();
                    }
                }
            } elseif (is_file($configFile = $bundleDir . $configFileDir . '.yml')) {
                $configFiles[] = $configFile;
            }

            foreach ($configFiles as $configFile) {
                $container->addResource(new FileResource($configFile));
                $this->registerJobs($registry, $configFile);
            }
        }
    }

    /**
     * @param Definition $definition
     * @param string     $configFile
     */
    protected function registerJobs(Definition $definition, $configFile)
    {
        $config = $this->processConfig(
            $this->yamlParser->parse(
                file_get_contents($configFile)
            )
        );

        foreach ($config['jobs'] as $alias => $job) {
            foreach ($job['steps'] as $step) {
{'fraction_non_alphanumeric': 0.12055813953488372, 'fraction_numerical': 0.0022325581395348836, 'mean_word_length': 2.593582887700535, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4662754', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1439, 'n_words': 279}