<commit_before><?php

namespace Bolt\EventListener;

use Bolt;
use Bolt\Controller\Zone;
use Bolt\Filesystem\Exception\IOException;
use Silex\Application;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
 * Initialisation checks at the start of boot.
 *
 * @internal Do not extend/call.
 *
 * @author <NAME> <<EMAIL>>
 */
class BootInitListener implements EventSubscriberInterface
{
    /** @var Application */
    private $app;

    /**
     * Constructor.
     *
     * @param Application $app
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    /**
     * Early boot functions.
     *
     * @param GetResponseEvent $event
     *
     * @return Response|null
     */
    public function onBootEarly(GetResponseEvent $event)
    {
        $verifier = $this->app['boot.validator'];
        $response = $verifier->checks();
        if (!$response instanceof Response) {
            return null;
        }

        $event->setResponse($response);
    }

    /**
     * Normal boot functions.
     *
     * @param GetResponseEvent $event
     *
     * @return Response|null
     */
    public function onBoot(GetResponseEvent $event)
    {
        // Twig globals
        $this->setGlobals(false);
        $this->setGlobals(true);

        // Final thing we do, if we're still standing, is to save our
        // configuration to cache
        if (!$this->app['config']->get('general/caching/config')) {
            return null;
        }

        $cacheFs = $this->app['filesystem']->getFilesystem('cache');
        try {
            $this->app['config']->cacheConfig($cacheFs, $this->app['environment']);
        } catch (IOException $e) {
            $response = $this->app['controller.exception']->genericException($e);
            $event->setResponse($response);
        }
    }

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            KernelEvents::REQUEST => [
                ['onBootEarly', Application::EARLY_EVENT],
                ['onBoot', 0],
            ],
        ];
    }

    /**
     * Get the parameters that will be used to update Bolt's registered Twig
     * globals.
     *<commit_msg>Cache config file in cache root as the loading is too early to know environment<commit_after><?php

namespace Bolt\EventListener;

use Bolt;
use Bolt\Controller\Zone;
use Bolt\Filesystem\Exception\IOException;
use Silex\Application;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
 * Initialisation checks at the start of boot.
 *
 * @internal Do not extend/call.
 *
 * @author <NAME> <<EMAIL>>
 */
class BootInitListener implements EventSubscriberInterface
{
    /** @var Application */
    private $app;

    /**
     * Constructor.
     *
     * @param Application $app
     */
    public function __construct(Application $app)
    {
        $this->app = $app;
    }

    /**
     * Early boot functions.
     *
     * @param GetResponseEvent $event
     *
     * @return Response|null
     */
    public function onBootEarly(GetResponseEvent $event)
    {
        $verifier = $this->app['boot.validator'];
        $response = $verifier->checks();
        if (!$response instanceof Response) {
            return null;
        }

        $event->setResponse($response);
    }

    /**
     * Normal boot functions.
     *
     * @param GetResponseEvent $event
     *
     * @return Response|null
     */
    public function onBoot(GetResponseEvent $event)
    {
        // Twig globals
        $this->setGlobals(false);
        $this->setGlobals(true);

        // Final thing we do, if we're still standing, is to save our
        // configuration to cache
        if (!$this->app['config']->get('general/caching/config')) {
            return null;
        }

        $cacheFs = $this->app['filesystem']->getFilesystem('cache');
        try {
            $this->app['config']->cacheConfig($cacheFs, '');
        } catch (IOException $e) {
            $response = $this->app['controller.exception']->genericException($e);
            $event->setResponse($response);
        }
    }

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            KernelEvents::REQUEST => [
                ['onBootEarly', Application::EARLY_EVENT],
                ['onBoot', 0],
            ],
        ];
    }

    /**
     * Get the parameters that will be used to update Bolt's registered Twig
     * globals.
     *
{'fraction_non_alphanumeric': 0.12750861544698966, 'fraction_numerical': 0.00040543279951348065, 'mean_word_length': 2.2805851063829787, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 42, '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': '7135342', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1373, 'n_words': 305}