<commit_before><?php

namespace DSpec\Console;

use DSpec\Container;
use DSpec\ServiceProviderInterface;
use DSpec\Provider\ConfigServiceProvider;
use DSpec\Console\Command\DSpecCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * This file is part of dspec
 *
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

class DSpecApplication extends Application
{
    protected $container;
    protected $registeredProviders = array();
    protected $name = 'dspec';

    /**
     * @param string $version
     */
    public function __construct(Container $container, $version = 'dev')
    {
        $this->container = $container;
        parent::__construct('dspec', $version);
    }

    public function getContainer()
    {
        return $this->container;
    }

    public function doRun(InputInterface $input, OutputInterface $output)
    {
        // introspect input without definition
        $config = $input->getParameterOption(array('--config', '-c'));
        $verbose = $input->getParameterOption(array('--verbose', '-v'));
        $bootstrap = $input->getParameterOption(array('--bootstrap', '-b'));
        $profile = $input->getParameterOption(array('--profile', '-p'));

        if (true == $verbose) {
            $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
        }

        $container = $this->getContainer();

        // event dispatcher 
        $container['dispatcher'] = new EventDispatcher;
        $container['input']  = $input;
        $container['output'] = $output;

        // config

        /**
         * Process options
         */
        $this->register(new ConfigServiceProvider(), array(
            'config.path' => $config,
        ));

        if ($profile) {
            $container['config.profile'] = $profile;
        }
        $overrides = array();
        if ($input->hasParameterOption(array('--verbose', '-v'))) {
            $overrides['verbose'] = true;
        }
        if ($bootstrap) {
            $overrides['bootstrap'] = $bootstrap;
        }
        $container['config.overrides'] = $overrides;

        /**
         * Should overwrite the profile with command line options here
         */
        if ($container['profile']->bootstrap) { 
            $inc = function() use ($container) {
                require $container['profile']->bootstrap;
            };
            $inc();
        }

        // extensions
        foreach($container['profile']->extensions as $name => $options) {
            $class = "\\DSpec\\Provider\\" . ucfirst($name) . "ServiceProvider";
            if (!class_exists($class)) {
                $class = $name;
                if (!class_exists($class)) {
                    throw new \InvalidArgumentException("class:$class not found");
                }
            } <commit_msg>Try and load config only once<commit_after><?php

namespace DSpec\Console;

use DSpec\Container;
use DSpec\ServiceProviderInterface;
use DSpec\Provider\ConfigServiceProvider;
use DSpec\Console\Command\DSpecCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
 * This file is part of dspec
 *
 * Copyright (c) 2012 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

class DSpecApplication extends Application
{
    protected $container;
    protected $registeredProviders = array();
    protected $name = 'dspec';

    /**
     * @param string $version
     */
    public function __construct(Container $container, $version = 'dev')
    {
        $this->container = $container;
        parent::__construct('dspec', $version);
    }

    public function getContainer()
    {
        return $this->container;
    }

    public function doRun(InputInterface $input, OutputInterface $output)
    {
        // introspect input without definition
        $config = $input->getParameterOption(array('--config', '-c'));
        $verbose = $input->getParameterOption(array('--verbose', '-v'));
        $bootstrap = $input->getParameterOption(array('--bootstrap', '-b'));
        $profile = $input->getParameterOption(array('--profile', '-p'));

        if (true == $verbose) {
            $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
        }

        $container = $this->getContainer();

        // event dispatcher 
        $container['dispatcher'] = new EventDispatcher;
        $container['input']  = $input;
        $container['output'] = $output;

        // config

        /**
         * Process options
         */
        $this->register(new ConfigServiceProvider(), array(
            'config.path' => $config,
        ));

        if ($profile) {
            $container['config.profile'] = $profile;
        }
        $overrides = array();
        if ($input->hasParameterOption(array('--verbose', '-v'))) {
            $overrides['verbose'] = true;
        }
        if ($bootstrap) {
            $overrides['bootstrap'] = $bootstrap;
        }
        $container['config.overrides'] = $overrides;

        /**
         * Should overwrite the profile with command line options here
         */
        $profile = $container['profile'];
        if ($profile->bootstrap) { 
            $inc = function() use ($profile) {
                require $profile->bootstrap;
            };
            $inc();
        }

        // extensions
        foreach($profile->extensions as $name => $options) {
            $class = "\\DSpec\\Provider\\" . ucfirst($name) . "ServiceProvider";
            if (!class_exists($class)) {
                $class = $name;
                if (!class_exists($class)) {
                    throw new \InvalidArgumentException("class:$class not found");
                }
            } 
{'fraction_non_alphanumeric': 0.13784577345078042, 'fraction_numerical': 0.0012362849636841293, 'mean_word_length': 2.422527763088313, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4996931', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1673, 'n_words': 377}