<commit_before><?php

/*
 * This file is part of the Panda framework.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Panda\Foundation\Http;

use InvalidArgumentException;
use Panda\Contracts\Http\Kernel as KernelInterface;
use Panda\Foundation\Application;
use Panda\Foundation\Bootstrap\Configuration;
use Panda\Foundation\Bootstrap\DateTimer;
use Panda\Foundation\Bootstrap\Environment;
use Panda\Foundation\Bootstrap\FacadeRegistry;
use Panda\Foundation\Bootstrap\Localization;
use Panda\Foundation\Bootstrap\Logging;
use Panda\Foundation\Bootstrap\Session;
use Panda\Http\Request;
use Panda\Http\Response;
use Panda\Routing\Controller;
use Panda\Routing\Router;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

/**
 * Class Kernel
 * @package Panda\Foundation\Http
 */
class Kernel implements KernelInterface
{
    /**
     * @var Application
     */
    protected $app;

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

    /**
     * @var string[]
     */
    protected $bootstrappers = [
        Environment::class,
        Configuration::class,
        Logging::class,
        FacadeRegistry::class,
        Localization::class,
        DateTimer::class,
        Session::class,
    ];

    /**
     * Kernel constructor.
     *
     * @param Application $app
     * @param Router      $router
     */
    public function __construct(Application $app, Router $router)
    {
        $this->app = $app;
        $this->router = $router;
    }

    /**
     * Init the panda application and start all the interfaces that
     * are needed for runtime.
     *
     * @param Request|SymfonyRequest $request
     *
     * @throws InvalidArgumentException
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     */
    public function boot($request)
    {
        // Check arguments
        if (empty($request) || !($request instanceof SymfonyRequest)) {
            throw new InvalidArgumentException('Request is empty or not valid.');
        }

        // Initialize application
        $this->getApp()->boot($request, $this->bootstrappers);

        // Set base controller router
        Controller::setRouter($this->getRouter());

        // Include routes
        include_once $this->getApp()->getRoutesPath();
    }

    /**
     * Handle the incoming request and return a response.
     *
     * @param Request|SymfonyRequest $request
     *
     * @return Response
     * @throws InvalidArgumentException
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     * @throws \LogicException
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
     * @throws \UnexpectedValueException
     */
    public function handle(SymfonyRequest $request)<commit_msg>[Framework] Set Kernel to use RoutesConfiguationHandler<commit_after><?php

/*
 * This file is part of the Panda framework.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Panda\Foundation\Http;

use InvalidArgumentException;
use Panda\Contracts\Http\Kernel as KernelInterface;
use Panda\Foundation\Application;
use Panda\Foundation\Bootstrap\Configuration;
use Panda\Foundation\Bootstrap\Environment;
use Panda\Foundation\Bootstrap\FacadeRegistry;
use Panda\Foundation\Bootstrap\Localization;
use Panda\Foundation\Bootstrap\Logging;
use Panda\Http\Request;
use Panda\Http\Response;
use Panda\Routing\Controller;
use Panda\Routing\Router;
use Panda\Support\Configuration\RoutesConfigurationHandler;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

/**
 * Class Kernel
 * @package Panda\Foundation\Http
 */
class Kernel implements KernelInterface
{
    /**
     * @var Application
     */
    protected $app;

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

    /**
     * @var string[]
     */
    protected $bootstrappers = [
        Environment::class,
        Configuration::class,
        Logging::class,
        FacadeRegistry::class,
        Localization::class,
    ];

    /**
     * @var RoutesConfigurationHandler
     */
    private $routesConfigurationHandler;

    /**
     * Kernel constructor.
     *
     * @param Application                $app
     * @param Router                     $router
     * @param RoutesConfigurationHandler $routesConfigurationHandler
     */
    public function __construct(Application $app, Router $router, RoutesConfigurationHandler $routesConfigurationHandler)
    {
        $this->app = $app;
        $this->router = $router;
        $this->routesConfigurationHandler = $routesConfigurationHandler;
    }

    /**
     * Init the panda application and start all the interfaces that
     * are needed for runtime.
     *
     * @param Request|SymfonyRequest $request
     *
     * @throws InvalidArgumentException
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     */
    public function boot($request)
    {
        // Check arguments
        if (empty($request) || !($request instanceof SymfonyRequest)) {
            throw new InvalidArgumentException('Request is empty or not valid.');
        }

        // Initialize application
        $this->getApp()->boot($request, $this->bootstrappers);

        // Set base controller router
        Controller::setRouter($this->getRouter());

        // Include routes
        include_once $this->routesConfigurationHandler->getRoutesPath($this->getApp()->getBasePath());
    }

    /**
     * Handle the incoming request and return a response.
     *
     * @param Request|SymfonyRequest $request
     *
     * @return Response
     * @throws InvalidArgumentException
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     * @throws \LogicException
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
     * @throws \UnexpectedValueException
     */
    public function handle(SymfonyRequest $request)
{'fraction_non_alphanumeric': 0.10356971346246198, 'fraction_numerical': 0.0, 'mean_word_length': 2.8759305210918114, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '5900633', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1648, 'n_words': 409}