<commit_before><?php
/**
 * MageSpec
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the MIT License, that is bundled with this
 * package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 *
 * http://opensource.org/licenses/MIT
 *
 * If you did not receive a copy of the license and are unable to obtain it
 * through the world-wide-web, please send an email
 * to <<EMAIL>> so we can send you a copy immediately.
 *
 * @category   MageTest
 * @package    PhpSpec_MagentoExtension
 *
 * @copyright  Copyright (c) 2012-2013 MageTest team and contributors.
 */
namespace MageTest\PhpSpec\MagentoExtension;

use PhpSpec\Extension\ExtensionInterface;
use PhpSpec\Console\ExtendableApplicationInterface as ApplicationInterface;
use PhpSpec\ServiceContainer;

use MageTest\PhpSpec\MagentoExtension\Runner\Maintainer\VarienSubjectMaintainer;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeModelCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ModelLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ModelGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeResourceModelCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ResourceModelLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ResourceModelGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeBlockCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\BlockLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\BlockGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeHelperCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\HelperLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\HelperGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeControllerCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ControllerLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ControllerGenerator;

/**
 * Extension
 *
 * @category   MageTest
 * @package    PhpSpec_MagentoExtension
 *
 * @author     MageTest team (https://github.com/MageTest/MageSpec/contributors)
 */
class Extension implements ExtensionInterface
{
    public function load(ServiceContainer $container)
    {
        $container->setShared('console.commands.describe_model', function ($c) {
            return new DescribeModelCommand();
        });

        $container->setShared('code_generator.generators.mage_model', function($c) {
            return new ModelGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_resource_model', function ($c) {
            return new DescribeResourceModelCommand();
        });

        $container->setShared('code_generator.generators.mage_resource_model', function($c) {
            return new ResourceModelGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_block', function ($c) {
            return new DescribeBlockCommand();
        });

        $container->setShared('code_generator.generators.mage_block', function($c) {
            return new BlockGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_helper', function ($c) {
            return new DescribeHelperCommand();
        });

        $container->setShared('code_generator.generators.mage_helper', function($c) {
            return new HelperGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_controller', function ($c) {
            return new DescribeControllerCommand();
        });

        $container->setShared('code_generator.generators.mage_controller', function($c) {
            return new ControllerGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('runner.maintainers.varien_subject', function($c) {
            return new VarienSubjectMaintainer(
                $c->get('formatter.presenter'),
                $c->get('unwrapper')
            );
        });

        $container->addConfigurator(function($c) {
            $suite = $c->getParam('mage_locator', array('main' => ''));

            $srcNS      = isset($suite['namespace']) ? $suite['namespace'] : '';
            $specPrefix = isset($suite['spec_prefix']) ? $suite['spec_prefix'] : '';
            $srcPath    = isset($suite['src_path']) ? rtrim($suite['src_path'], '/') . DIRECTORY_SEPARATOR : 'src';
            $specPath   = isset($suite['spec_path']) ? rtrim($suite['spec_path'], '/') . DIRECTORY_SEPARATOR : '.';

            if (!is_dir($srcPath)) {
                mkdir($srcPath, 0777, true);
            }
            if (!is_dir($specPath)) {
                mkdir($specPath, 0777, true);
            }

            $c->setShared('locator.locators.model_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new ModelLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.resource_model_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new ResourceModelLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.block_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new BlockLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.helper_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new HelperLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.controller_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new ControllerLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );
        });
    }
}<commit_msg>Extension should bootstrap Magento<commit_after><?php
/**
 * MageSpec
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the MIT License, that is bundled with this
 * package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 *
 * http://opensource.org/licenses/MIT
 *
 * If you did not receive a copy of the license and are unable to obtain it
 * through the world-wide-web, please send an email
 * to <<EMAIL>> so we can send you a copy immediately.
 *
 * @category   MageTest
 * @package    PhpSpec_MagentoExtension
 *
 * @copyright  Copyright (c) 2012-2013 MageTest team and contributors.
 */
namespace MageTest\PhpSpec\MagentoExtension;

use PhpSpec\Extension\ExtensionInterface;
use PhpSpec\Console\ExtendableApplicationInterface as ApplicationInterface;
use PhpSpec\ServiceContainer;

use MageTest\PhpSpec\MagentoExtension\Runner\Maintainer\VarienSubjectMaintainer;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeModelCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ModelLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ModelGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeResourceModelCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ResourceModelLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ResourceModelGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeBlockCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\BlockLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\BlockGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeHelperCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\HelperLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\HelperGenerator;

use MageTest\PhpSpec\MagentoExtension\Console\Command\DescribeControllerCommand;
use MageTest\PhpSpec\MagentoExtension\Locator\Magento\ControllerLocator;
use MageTest\PhpSpec\MagentoExtension\CodeGenerator\Generator\ControllerGenerator;

/**
 * Extension
 *
 * @category   MageTest
 * @package    PhpSpec_MagentoExtension
 *
 * @author     MageTest team (https://github.com/MageTest/MageSpec/contributors)
 */
class Extension implements ExtensionInterface
{
    public function load(ServiceContainer $container)
    {
        $container->setShared('console.commands.describe_model', function ($c) {
            return new DescribeModelCommand();
        });

        $container->setShared('code_generator.generators.mage_model', function($c) {
            return new ModelGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_resource_model', function ($c) {
            return new DescribeResourceModelCommand();
        });

        $container->setShared('code_generator.generators.mage_resource_model', function($c) {
            return new ResourceModelGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_block', function ($c) {
            return new DescribeBlockCommand();
        });

        $container->setShared('code_generator.generators.mage_block', function($c) {
            return new BlockGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_helper', function ($c) {
            return new DescribeHelperCommand();
        });

        $container->setShared('code_generator.generators.mage_helper', function($c) {
            return new HelperGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('console.commands.describe_controller', function ($c) {
            return new DescribeControllerCommand();
        });

        $container->setShared('code_generator.generators.mage_controller', function($c) {
            return new ControllerGenerator(
                $c->get('console.io'),
                $c->get('code_generator.templates')
            );
        });

        $container->setShared('runner.maintainers.varien_subject', function($c) {
            return new VarienSubjectMaintainer(
                $c->get('formatter.presenter'),
                $c->get('unwrapper')
            );
        });

        $container->addConfigurator(function($c) {
            $suite = $c->getParam('mage_locator', array('main' => ''));

            $srcNS      = isset($suite['namespace']) ? $suite['namespace'] : '';
            $specPrefix = isset($suite['spec_prefix']) ? $suite['spec_prefix'] : '';
            $srcPath    = isset($suite['src_path']) ? rtrim($suite['src_path'], '/') . DIRECTORY_SEPARATOR : 'src';
            $specPath   = isset($suite['spec_path']) ? rtrim($suite['spec_path'], '/') . DIRECTORY_SEPARATOR : '.';

            if (!is_dir($srcPath)) {
                mkdir($srcPath, 0777, true);
            }
            if (!is_dir($specPath)) {
                mkdir($specPath, 0777, true);
            }

            $c->setShared('locator.locators.model_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new ModelLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.resource_model_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new ResourceModelLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.block_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new BlockLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.helper_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new HelperLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );

            $c->setShared('locator.locators.controller_locator',
                function($c) use($srcNS, $specPrefix, $srcPath, $specPath) {
                    return new ControllerLocator($srcNS, $specPrefix, $srcPath, $specPath);
                }
            );
        });

        $this->bootstrap();
    }

    private function bootstrap()
    {
        \Mage::app();
    }
}
{'fraction_non_alphanumeric': 0.12488755622188906, 'fraction_numerical': 0.0023988005997001498, 'mean_word_length': 2.6884158142106718, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 70, 'https://': 2, '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': '2269403', 'n_tokens_mistral': 3800, 'n_tokens_neox': 3678, 'n_words': 608}