<commit_before><?php

namespace Laracasts\Behat\ServiceContainer;

use Behat\Behat\Context\ServiceContainer\ContextExtension;
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
use Behat\Testwork\ServiceContainer\Extension;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Laracasts\Behat\ServiceContainer\LaravelFactory;

class LaravelExtension implements Extension
{

    /**
     * {@inheritdoc}
     */
    public function getConfigKey()
    {
        return 'laravel';
    }

    /**
     * {@inheritdoc}
     */
    public function initialize(ExtensionManager $extensionManager)
    {
        if (null !== $minkExtension = $extensionManager->getExtension('mink')) {
            $minkExtension->registerDriverFactory(new LaravelFactory);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        //
    }

    /**
     * {@inheritdoc}
     */
    public function configure(ArrayNodeDefinition $builder)
    {
        $builder
            ->children()
                ->scalarNode('bootstrap_path')
                    ->defaultValue('foobar')
                ->end()
                ->scalarNode('env_path')
                    ->defaultValue('.env.behat');
    }

    /**
     * {@inheritdoc}
     */
    public function load(ContainerBuilder $container, array $config)
    {
        $this->loadApplication($container, $config);
        $this->loadInitializer($container);
    }

    /**
     * Boot up Laravel.
     *
     * @param ContainerBuilder $container
     * @param array            $config
     */
    private function loadApplication(ContainerBuilder $container, array $config)
    {
        $app = require __DIR__ . '/../../../../../bootstrap/app.php';

        $app->loadEnvironmentFrom($config['env_path']);

        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

        $container->register('laravel.app', $app);
    }

    /**
     * Load the initializer.
     *
     * @param ContainerBuilder $container
     */
    private function loadInitializer(ContainerBuilder $container)
    {
        $definition = new Definition('Laracasts\Behat\Context\KernelAwareInitializer', [
            new Reference('laravel.app')
        ]);<commit_msg>Use correct bootstrap path<commit_after><?php

namespace Laracasts\Behat\ServiceContainer;

use Behat\Behat\Context\ServiceContainer\ContextExtension;
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
use Behat\Testwork\ServiceContainer\Extension;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Laracasts\Behat\ServiceContainer\LaravelFactory;

class LaravelExtension implements Extension
{

    /**
     * {@inheritdoc}
     */
    public function getConfigKey()
    {
        return 'laravel';
    }

    /**
     * {@inheritdoc}
     */
    public function initialize(ExtensionManager $extensionManager)
    {
        if (null !== $minkExtension = $extensionManager->getExtension('mink')) {
            $minkExtension->registerDriverFactory(new LaravelFactory);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        //
    }

    /**
     * {@inheritdoc}
     */
    public function configure(ArrayNodeDefinition $builder)
    {
        $builder
            ->children()
                ->scalarNode('bootstrap_path')
                    ->defaultValue('bootstrap/app.php')
                ->end()
                ->scalarNode('env_path')
                    ->defaultValue('.env.behat');
    }

    /**
     * {@inheritdoc}
     */
    public function load(ContainerBuilder $container, array $config)
    {
        $this->loadApplication($container, $config);
        $this->loadInitializer($container);
    }

    /**
     * Boot up Laravel.
     *
     * @param ContainerBuilder $container
     * @param array            $config
     */
    private function loadApplication(ContainerBuilder $container, array $config)
    {
        $bootstrapPath = $container->getParameter('paths.base') . '/bootstrap/app.php';

        $app = require $bootstrapPath;

        $app->loadEnvironmentFrom($config['env_path']);

        $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

        $container->register('laravel.app', $app);
    }

    /**
     * Load the initializer.
     *
     * @param ContainerBuilder $container
     */
    private function loadInitializer(ContainerBuilder $container)
    {
        $definition = new Definition('Laracasts\Behat\Context\KernelAwareInitializer', [
            new Reference('laravel.app')
        ]);
{'fraction_non_alphanumeric': 0.12250879249706917, 'fraction_numerical': 0.0, 'mean_word_length': 2.6176678445229684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '2354516', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1332, 'n_words': 219}