<commit_before><?php

namespace Rad;

use App\Bootstrap;
use Rad\Core\Action\MissingMethodException;
use Rad\Core\DotEnv;
use Rad\Core\Responder;
use Rad\Core\SingletonTrait;
use Rad\DependencyInjection\Di;
use Rad\DependencyInjection\DiInterface;
use Rad\Http\Exception\NotFoundException;
use Rad\Http\Request;
use Rad\Http\RequestInterface;
use Rad\Http\Response;
use Rad\Http\ResponseInterface;
use Rad\Routing\Router;

/**
 * Application
 *
 * @package Rad
 */
class Application
{
    use SingletonTrait;

    /**
     * @var DiInterface
     */
    protected $di;

    /**
     * @var Router
     */
    protected $router;

    /**
     * @var RequestInterface
     */
    protected $request;

    /**
     * @var ResponseInterface
     */
    protected $response;

    /**
     * Init application
     *
     * @throws Exception
     */
    protected function init()
    {
        DotEnv::load(dirname(dirname(dirname(dirname(__DIR__)))));
        if (!getenv('RAD_ENV')) {
            putenv('RAD_ENV=production');
        }

        $this->di = new Di();
        $this->di->setShared('request', $this->request = new Request());
        $this->di->setShared('response', $this->response = new Response());
        $this->di->setShared('router', $this->router = new Router());
        $this->di->setShared('cookies', new Response\Cookies());

        $appBootstrap = new Bootstrap();
        $appBootstrap->setDi($this->di);
    }

    /**
     * Run application
     *
     * @throws MissingMethodException
     * @throws NotFoundException
     */
    public function run()
    {
        $this->di->get('router')->handle();
        $this->callAction();
    }

    /**
     * Call Action
     *
     * @throws MissingMethodException
     * @throws NotFoundException
     */
    protected function callAction()
    {
        $method = strtolower($this->request->getMethod());
        $actionNamespace = $this->router->getActionNamespace();

        if ($this->router->wasMatched() && is_subclass_of($actionNamespace, 'App\\Action\\AppAction')) {
            if (method_exists($actionNamespace, $method) && is_callable([$actionNamespace, $method])) {
                $responder = $this->callResponder();
                $instance = new $actionNamespace($responder);
                $instance->setDi($this->di);
                call_user_func_array([$instance, $method], $this->router->getParams());
<commit_msg>Check application is run<commit_after><?php

namespace Rad;

use App\Bootstrap;
use Rad\Core\Action\MissingMethodException;
use Rad\Core\DotEnv;
use Rad\Core\Responder;
use Rad\Core\SingletonTrait;
use Rad\DependencyInjection\Di;
use Rad\DependencyInjection\DiInterface;
use Rad\Http\Exception\NotFoundException;
use Rad\Http\Request;
use Rad\Http\RequestInterface;
use Rad\Http\Response;
use Rad\Http\ResponseInterface;
use Rad\Routing\Router;

/**
 * Application
 *
 * @package Rad
 */
class Application
{
    use SingletonTrait;

    /**
     * @var DiInterface
     */
    protected $di;

    /**
     * @var Router
     */
    protected $router;

    /**
     * @var RequestInterface
     */
    protected $request;

    /**
     * @var ResponseInterface
     */
    protected $response;
    protected $isRun = false;

    /**
     * Init application
     *
     * @throws Exception
     */
    protected function init()
    {
        DotEnv::load(dirname(dirname(dirname(dirname(__DIR__)))));
        if (!getenv('RAD_ENV')) {
            putenv('RAD_ENV=production');
        }

        $this->di = new Di();
        $this->di->setShared('request', $this->request = new Request());
        $this->di->setShared('response', $this->response = new Response());
        $this->di->setShared('router', $this->router = new Router());
        $this->di->setShared('cookies', new Response\Cookies());

        $appBootstrap = new Bootstrap();
        $appBootstrap->setDi($this->di);
    }

    /**
     * Run application
     *
     * @throws MissingMethodException
     * @throws NotFoundException
     */
    public function run()
    {
        if (!$this->isRun) {
            $this->di->get('router')->handle();
            $this->callAction();
        } else {
            throw new Exception('Application is run.');
        }
    }

    /**
     * Call Action
     *
     * @throws MissingMethodException
     * @throws NotFoundException
     */
    protected function callAction()
    {
        $method = strtolower($this->request->getMethod());
        $actionNamespace = $this->router->getActionNamespace();

        if ($this->router->wasMatched() && is_subclass_of($actionNamespace, 'App\\Action\\AppAction')) {
            if (method_exists($actionNamespace, $method) && is_callable([$actionNamespace, $method])) {
                $responder = $this->callResponder();
                $instance = new $actionNamespace($responder);
                $instance->setDi($this->di);
                call_user_func_array([$instance, $method], $this->router->getParams());

{'fraction_non_alphanumeric': 0.15213469633193025, 'fraction_numerical': 0.0, 'mean_word_length': 2.519040902679831, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, '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': '615540', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1424, 'n_words': 268}