<commit_before><?php

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

namespace Symfony\Bundle\WebProfilerBundle;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\RequestEventArgs;
use Symfony\Bundle\TwigBundle\TwigEngine;

/**
 * WebDebugToolbarListener injects the Web Debug Toolbar.
 *
 * The handle method must be connected to the filterCoreResponse event.
 *
 * The WDT is only injected on well-formed HTML (with a proper </body> tag).
 * This means that the WDT is never included in sub-requests or ESI requests.
 *
 * @author <NAME> <<EMAIL>>
 */
class WebDebugToolbarListener
{
    protected $kernel;
    protected $templating;
    protected $interceptRedirects;

    public function __construct(HttpKernel $kernel, TwigEngine $templating, $interceptRedirects = false)
    {
        $this->kernel = $kernel;
        $this->templating = $templating;
        $this->interceptRedirects = $interceptRedirects;
    }

    public function filterCoreResponse(RequestEventArgs $eventArgs)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
            return;
        }

        $response = $eventArgs->getResponse();
        if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
            $response->setContent(
                sprintf('<html><head></head><body><h1>This Request redirects to<br /><a href="%1$s">%1$s</a>.</h1><h4>The redirect was intercepted by the web debug toolbar to help debugging.<br/>For more information, see the "intercept-redirects" option of the Profiler.</h4></body></html>',
                $response->headers->get('Location'))
            );
            $response->setStatusCode(200);
            $response->headers->remove('Location');
        }

        $request = $eventArgs->getRequest();
        if (!$response->headers->has('X-Debug-Token')
            || '3' === substr($response->getStatusCode(), 0, 1)<commit_msg>Renamed EventArgs classes and adapted remaining code to EventManager<commit_after><?php

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

namespace Symfony\Bundle\WebProfilerBundle;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEventArgs;
use Symfony\Bundle\TwigBundle\TwigEngine;

/**
 * WebDebugToolbarListener injects the Web Debug Toolbar.
 *
 * The handle method must be connected to the filterCoreResponse event.
 *
 * The WDT is only injected on well-formed HTML (with a proper </body> tag).
 * This means that the WDT is never included in sub-requests or ESI requests.
 *
 * @author <NAME> <<EMAIL>>
 */
class WebDebugToolbarListener
{
    protected $kernel;
    protected $templating;
    protected $interceptRedirects;

    public function __construct(HttpKernel $kernel, TwigEngine $templating, $interceptRedirects = false)
    {
        $this->kernel = $kernel;
        $this->templating = $templating;
        $this->interceptRedirects = $interceptRedirects;
    }

    public function filterCoreResponse(FilterResponseEventArgs $eventArgs)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $eventArgs->getRequestType()) {
            return;
        }

        $response = $eventArgs->getResponse();
        if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
            $response->setContent(
                sprintf('<html><head></head><body><h1>This Request redirects to<br /><a href="%1$s">%1$s</a>.</h1><h4>The redirect was intercepted by the web debug toolbar to help debugging.<br/>For more information, see the "intercept-redirects" option of the Profiler.</h4></body></html>',
                $response->headers->get('Location'))
            );
            $response->setStatusCode(200);
            $response->headers->remove('Location');
        }

        $request = $eventArgs->getRequest();
        if (!$response->headers->has('X-Debug-Token')
            || '3' === substr($response->getStatusCode(), 0, 1)
{'fraction_non_alphanumeric': 0.12771447000645023, 'fraction_numerical': 0.005160180606321221, 'mean_word_length': 3.52089407191448, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 83, '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': '2821822', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1290, 'n_words': 335}