<commit_before><?php

/**
 * Brings Twig to Laravel 4.
 *
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */

namespace TwigBridge;

use Illuminate\View\ViewServiceProvider;
use Twig_Loader_Chain;
use TwigBridge\Console\ClearCommand;

/**
 * Bootstrap Laravel Twig(Bridge).
 */
class TwigServiceProvider extends ViewServiceProvider
{
    /**
     * {@inheritdoc}
     */
    public function register()
    {
        // Register the package configuration with the loader.
        $this->app['config']->package('rcrowe/twigbridge', __DIR__.'/Config');
    }

    /**
     * {@inheritdoc}
     */
    public function boot()
    {
        $this->registerTwigEngine();
        $this->registerCommands();
    }

    /**
     * Register the Twig engine.
     *
     * @return void
     */
    public function registerTwigEngine()
    {
        $app = $this->app;

        // Extensions
        $app['twig.extensions'] = $app->share(function () use ($app) {
            $extensions = $app['config']->get('twigbridge::extensions.enabled', array());

            // Is debug enabled?
            $options = $app['twig.options'];
            $debug   = (bool) (isset($options['debug'])) ? $options['debug'] : false;

            if ($debug) {
                array_unshift($extensions, 'Twig_Extension_Debug');
            }

            return $extensions;
        });

        // Loader
        $app['twig.loader.path'] = $app->share(function () {
            return new Twig\Loader\Path;
        });

        $app['twig.loader.viewfinder'] = $app->share(function () use ($app) {
            return new Twig\Loader\Viewfinder(
                $app['view']->getFinder(),
                $app['twig.bridge']->getExtension()
            );
        });

        $app['twig.loader'] = $app->share(function () use ($app) {
            return new Twig_Loader_Chain(array(
                $app['twig.loader.path'],
                $app['twig.loader.viewfinder'],
            ));
        });

        // Twig
        $app['twig.options'] = $app->share(function () use ($app) {
            $options = $app['config']->get('twigbridge::twig.environment', array());

            // Check whether we have the cache path set
            if (empty($options['cache'])) {
                // No cache path set for Twig, lets set to the Laravel views storage folder
                $options['cache'] = $app['path.storage'].'/views/twig';
            }

            return $options;
        });

        $app['twig.bridge'] = $app->share(function () use ($app) {
            return new TwigBridge($app);
        });

        $app['twig'] = $app->share(function () use ($app) {
            return $app['twig.bridge']->getTwig();
        });

        // Engine
        $app['twig.engine'] = $app->share(function () use ($app) {
            return new Engine\Twig(
                $app['twig'],
                $app['config']->get('twigbridge::twig.globals', array())
            );
        });

        $app['view']->addExtension(
            $app['config']->get('twigbridge::twig.extension', 'twig'),
            'twig',
            function () use ($app) {
                return $app['twig.engine'];
            }
        );
    }

    /**
     * Register the cache related console commands.
     *
     * @return void
     */
    public function registerCommands()
    {
        $this->app['command.twig.clear'] = $this->app->share(
            function ($app) {
                return new ClearCommand($app['twig'], $app['files']);
            }
        );

        $this->commands(
            'command.twig.clear'
        );<commit_msg>No need to use here<commit_after><?php

/**
 * Brings Twig to Laravel 4.
 *
 * @author <NAME> <<EMAIL>>
 * @license MIT
 */

namespace TwigBridge;

use Illuminate\View\ViewServiceProvider;
use Twig_Loader_Chain;

/**
 * Bootstrap Laravel Twig(Bridge).
 */
class TwigServiceProvider extends ViewServiceProvider
{
    /**
     * {@inheritdoc}
     */
    public function register()
    {
        // Register the package configuration with the loader.
        $this->app['config']->package('rcrowe/twigbridge', __DIR__.'/Config');
    }

    /**
     * {@inheritdoc}
     */
    public function boot()
    {
        $this->registerTwigEngine();
        $this->registerCommands();
    }

    /**
     * Register the Twig engine.
     *
     * @return void
     */
    public function registerTwigEngine()
    {
        $app = $this->app;

        // Extensions
        $app['twig.extensions'] = $app->share(function () use ($app) {
            $extensions = $app['config']->get('twigbridge::extensions.enabled', array());

            // Is debug enabled?
            $options = $app['twig.options'];
            $debug   = (bool) (isset($options['debug'])) ? $options['debug'] : false;

            if ($debug) {
                array_unshift($extensions, 'Twig_Extension_Debug');
            }

            return $extensions;
        });

        // Loader
        $app['twig.loader.path'] = $app->share(function () {
            return new Twig\Loader\Path;
        });

        $app['twig.loader.viewfinder'] = $app->share(function () use ($app) {
            return new Twig\Loader\Viewfinder(
                $app['view']->getFinder(),
                $app['twig.bridge']->getExtension()
            );
        });

        $app['twig.loader'] = $app->share(function () use ($app) {
            return new Twig_Loader_Chain(array(
                $app['twig.loader.path'],
                $app['twig.loader.viewfinder'],
            ));
        });

        // Twig
        $app['twig.options'] = $app->share(function () use ($app) {
            $options = $app['config']->get('twigbridge::twig.environment', array());

            // Check whether we have the cache path set
            if (empty($options['cache'])) {
                // No cache path set for Twig, lets set to the Laravel views storage folder
                $options['cache'] = $app['path.storage'].'/views/twig';
            }

            return $options;
        });

        $app['twig.bridge'] = $app->share(function () use ($app) {
            return new TwigBridge($app);
        });

        $app['twig'] = $app->share(function () use ($app) {
            return $app['twig.bridge']->getTwig();
        });

        // Engine
        $app['twig.engine'] = $app->share(function () use ($app) {
            return new Engine\Twig(
                $app['twig'],
                $app['config']->get('twigbridge::twig.globals', array())
            );
        });

        $app['view']->addExtension(
            $app['config']->get('twigbridge::twig.extension', 'twig'),
            'twig',
            function () use ($app) {
                return $app['twig.engine'];
            }
        );
    }

    /**
     * Register the cache related console commands.
     *
     * @return void
     */
    public function registerCommands()
    {
        $this->app['command.twig.clear'] = $this->app->share(
            function ($app) {
                return new Console\ClearCommand($app['twig'], $app['files']);
            }
        );

        $this->commands(
            'command.twig.clear'
        );
{'fraction_non_alphanumeric': 0.1684971500069512, 'fraction_numerical': 0.00027804810232170165, 'mean_word_length': 1.7647963105303612, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 59, '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': '4303920', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2043, 'n_words': 390}