<commit_before><?php
namespace Hope;

use Hope\Contracts\HttpExceptionInterface;
use Hope\Contracts\OutputerInterface;
use Hope\Contracts\ProviderInterface;
use Hope\DIContainer;
use Hope\Database\DatabaseProvider;
use Hope\Exceptions\InvalidProviderException;
use Hope\Http\RequestProvider;
use Hope\Outputer\OutputerProvider;
use Hope\Providers\ApplicationProvider;
use Hope\Router\Dispatcher;

/**
 * Hope Application base class
 *
 * @package Hope
 *
 * @author <NAME> <<EMAIL>>
 */
class Application extends DIContainer
{
    /**
     * List of Hope Providers
     *
     * @var array
     */
    private $providers = [
        ApplicationProvider::class,
        RequestProvider::class,
        OutputerProvider::class
    ];

    /**
     * Initialization
     */
    public function __construct(string $basePath = null)
    {
        if (isset($basePath)) {
            $this->setBasePath($basePath);
        }

        $this->initContainer();
        $this->registerBaseBindings();
    }

    /**
     * Register the basic bindings into the container.
     *
     * @return void
     */
    protected function registerBaseBindings()
    {
        static::setInstance($this);

        $this->bind('app', $this);

        $this->bind('Hope\DIContainer', $this);
    }

    /**
     * Set the base path for the application.
     *
     * @param  string  $basePath
     * @return $this
     */
    public function setBasePath($basePath)
    {
        $this->basePath = rtrim($basePath, '\/');

        return $this;
    }

    /**
     * Get the base path of the Laravel installation.
     *
     * @return string
     */
    public function basePath()
    {
        return $this->basePath;
    }

    /**
     * Get configuration data
     *
     * @param string $key Config item.
     *
     * @return mixed Config value
     */
    public static function config(string $key = null)
    {
        static $config;

        if (is_null($config)) {
            $config = require $this->basePath() . '/config/config.php';
        }

        if ($key) {
            return isset($config[$key]) ? $config[$key] : null;
        }

        return $config;
    }

    /**
     * Get all providers
     *
     * @return array List of providers
     */
    private function loadProvidersList()
    {
        $app_providers = include $this->basePath() . '/config/providers.php';
        return $this->providers + $app_providers;
    }

    /**
     * Registration of Providers
     *
     * @return void
     *
     * @throws InvalidProviderException Invalid provider.
     */
    private function registerProviders()
    {
        foreach ($this->loadProvidersList() as $provider) {
            if (!in_array(ProviderInterface::class, class_implements($provider))) {
                throw new InvalidProviderException(
                    "Class '{$provider}' SHOULD implement ProviderInterface!"
                );
            }
            $provider::register($this);
        }
    }

    /**
     * Registration of Routes
     *
     * @return void
     */
    private function registerRoutes()
    {
        $this->call([Router::class, 'register']);
    }

    /**
     * Bootstrap application
     *
     * @return void
     */
    public function bootstrap()
    {
        $this->registerProviders();
        $this->buildContainer();
        $this->registerRoutes();
    }

    /**
     * Run application
     *
     * @return void
     */
    public function run()
    {
        $this->call([Application::class, 'performResponse']);
    }

    /**
     * Call Dispatcher and perform response
     *
     * @param Dispatcher        $dispatcher Router Dispatcher.
     * @param OutputerInterface $outputer   Injection of Outputer.
     *
     * @return void
     */
    public function performResponse(
        Dispatcher $dispatcher,
        OutputerInterface $outputer
    ) {
        try {
            $responseData = $dispatcher->dispatch();
            $outputer->output($responseData);
        } catch (HttpExceptionInterface $e) {
            $outputer->outputHttpError($e);
        } catch (\Exception $e) {
            $outputer->outputException($e);
        }
    }
}
<commit_msg>Removing necessity of external files (except routes)<commit_after><?php
namespace Hope;

use Hope\Contracts\HttpExceptionInterface;
use Hope\Contracts\OutputerInterface;
use Hope\Contracts\ProviderInterface;
use Hope\DIContainer;
use Hope\Exceptions\InvalidProviderException;
use Hope\Http\RequestProvider;
use Hope\Outputer\OutputerProvider;
use Hope\Providers\ApplicationProvider;
use Hope\Router\Dispatcher;

/**
 * Hope Application base class
 *
 * @package Hope
 *
 * @author <NAME> <<EMAIL>>
 */
class Application extends DIContainer
{
    /**
     * List of Hope Providers
     *
     * @var array
     */
    private $providers = [
        ApplicationProvider::class,
        RequestProvider::class,
        OutputerProvider::class
    ];

    /**
     * Initialization
     */
    public function __construct(string $basePath = null)
    {
        if (isset($basePath)) {
            $this->setBasePath($basePath);
        }

        $this->initContainer();
        $this->registerBaseBindings();
    }

    /**
     * Register the basic bindings into the container.
     *
     * @return void
     */
    protected function registerBaseBindings()
    {
        static::setInstance($this);

        $this->bind('app', $this);

        $this->bind('Hope\DIContainer', $this);
    }

    /**
     * Set the base path for the application.
     *
     * @param  string  $basePath
     * @return $this
     */
    public function setBasePath($basePath)
    {
        $this->basePath = rtrim($basePath, '\/');

        return $this;
    }

    /**
     * Get the base path of the Laravel installation.
     *
     * @return string
     */
    public function basePath()
    {
        return $this->basePath;
    }

    /**
     * Define externals providers
     *
     * @param array $providers Providers list
     *
     * @return void
     */
    private function addExternalProviders(array $providers)
    {
        $this->providers += $providers;
    }

    /**
     * Registration of Providers
     *
     * @return void
     *
     * @throws InvalidProviderException Invalid provider.
     */
    private function registerProviders()
    {
        foreach ($this->providers as $provider) {
            if (!in_array(ProviderInterface::class, class_implements($provider))) {
                throw new InvalidProviderException(
                    "Class '{$provider}' SHOULD implement ProviderInterface!"
                );
            }
            $provider::register($this);
        }
    }

    /**
     * Registration of Routes
     *
     * @return void
     */
    private function registerRoutes()
    {
        $this->call([Router::class, 'register']);
    }

    /**
     * Bootstrap application
     *
     * @return void
     */
    public function bootstrap()
    {
        $this->registerProviders();
        $this->buildContainer();
        $this->registerRoutes();
    }

    /**
     * Run application
     *
     * @return void
     */
    public function run()
    {
        $this->call([Application::class, 'performResponse']);
    }

    /**
     * Call Dispatcher and perform response
     *
     * @param Dispatcher        $dispatcher Router Dispatcher.
     * @param OutputerInterface $outputer   Injection of Outputer.
     *
     * @return void
     */
    public function performResponse(
        Dispatcher $dispatcher,
        OutputerInterface $outputer
    ) {
        try {
            $responseData = $dispatcher->dispatch();
            $outputer->output($responseData);
        } catch (HttpExceptionInterface $e) {
            $outputer->outputHttpError($e);
        } catch (\Exception $e) {
            $outputer->outputException($e);
        }
    }
}

{'fraction_non_alphanumeric': 0.12040557667934093, 'fraction_numerical': 0.0, 'mean_word_length': 1.9981003039513678, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 47, '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': '3784551', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2156, 'n_words': 478}