<commit_before><?php

/*
 * Copyright 2010 <NAME> <<EMAIL>>
 *
 * This file is part of Mandango.
 *
 * Mandango is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Mandango is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Mandango. If not, see <http://www.gnu.org/licenses/>.
 */

namespace Mandango\MandangoBundle\Command;

use Mandango\DataLoader;
use Mandango\MandangoBundle\Util;
use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Yaml;

/**
 * LoadFixturesCommand.
 *
 * @author <NAME> <<EMAIL>>
 */
class LoadFixturesCommand extends Command
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('mandango:load-fixtures')
            ->setDescription('Load fixtures.')
            ->addOption('append', null, InputOption::VALUE_OPTIONAL, 'Whether or not to append the data fixtures', false)
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('processing fixtures');

        $data = array();
        // application
        if (is_dir($dir = $this->container->getParameter('kernel.root_dir').'/fixtures/mandango')) {
            $finder = new Finder();
            foreach ($finder->files()->name('*.yml')->followLinks()->in($dir) as $file) {
                $data = Util::arrayDeepMerge($data, (array) Yaml::load($file));
            }
        }
        // bundles
        foreach ($this->container->get('kernel')->getBundles() as $bundle) {
            if (is_dir($dir = $bundle->getPath().'/Resources/fixtures/mandango'))
            {
                $finder = new Finder();
                foreach ($finder->files()->name('*.yml')->followLinks()->in($dir) as $file) {
                    $data = Utile::arrayDeepMerge($data, (array) Yaml::load($file));
                }
            }
        }

        if (!$data) {
            $output->writeln('there are not fixtures');

            return;
        }

        $output->writeln('loading fixtures');

        $dataLoader = new DataLoader($this->container->get('mandango'));
        $dataLoader->load($data, true);
    }
}<commit_msg>added option to select fixture<commit_after><?php

/*
 * Copyright 2010 <NAME> <<EMAIL>>
 *
 * This file is part of Mandango.
 *
 * Mandango is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Mandango is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Mandango. If not, see <http://www.gnu.org/licenses/>.
 */

namespace Mandango\MandangoBundle\Command;

use Mandango\DataLoader;
use Mandango\MandangoBundle\Util;
use Symfony\Bundle\FrameworkBundle\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Yaml\Yaml;

/**
 * LoadFixturesCommand.
 *
 * @author <NAME> <<EMAIL>>
 */
class LoadFixturesCommand extends Command
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('mandango:load-fixtures')
            ->setDescription('Load fixtures.')
            ->addOption('fixtures', null, InputOption::VALUE_OPTIONAL, 'The directory or file to load data fixtures from')
            ->addOption('append', null, InputOption::VALUE_OPTIONAL, 'Whether or not to append the data fixtures', false)
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('processing fixtures');

        $dirOrFile = $input->getOption('fixtures');
        if ($dirOrFile) {
            $dirOrFile = array($dirOrFile);
        } else {
            $dirOrFile = array();
            // application
            if (is_dir($dir = $this->container->getParameter('kernel.root_dir').'/fixtures/mandango')) {
                $dirOrFile[] = $dir;
            }
            // bundles
            foreach ($this->container->get('kernel')->getBundles() as $bundle) {
                if (is_dir($dir = $bundle->getPath().'/Resources/fixtures/mandango')) {
                    $dirOrFile[] = $dir;
                }
            }
        }

        $files = array();
        foreach ($dirOrFile as $dir) {
            if (is_file($dir)) {
                $files[] = $dir;
                continue;
            }
            if (is_dir($dir)) {
                $finder = new Finder();
                foreach ($finder->files()->name('*.yml')->followLinks()->in($dir) as $file) {
                    $files[] = $file;
                }
                continue;
            }

            throw new \InvalidArgumentException(sprintf('"%s" is not a dir or file.', $dir));
        }

        $data = array();
        foreach ($files as $file) {
            $data = Util::arrayDeepMerge($data, (array) Yaml::load($file));
        }

        if (!$data) {
            $output->writeln('there are not fixtures');

            return;
        }

        $output->writeln('loading fixtures');

        $dataLoader = new DataLoader($this->container->get('mandango'));
        $dataLoader->load($data, true);
    }
}
{'fraction_non_alphanumeric': 0.13176100628930817, 'fraction_numerical': 0.0015723270440251573, 'mean_word_length': 2.4217321140398065, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 61, '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': '4645171', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1710, 'n_words': 478}