<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 AppBundle\EventListener;

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use AppBundle\Twig\SourceCodeExtension;

/**
 * Defines the method that 'listens' to the 'kernel.controller' event, which is
 * triggered whenever a controller is executed in the application.
 * See http://symfony.com/doc/current/book/internals.html#kernel-controller-event
 *
 * Tip: listeners are common in Symfony applications, but this particular listener
 * is too advanced and too specific for the demo application needs. For more common
 * examples see http://symfony.com/doc/current/cookbook/service_container/event_listener.html
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ControllerListener
{
    protected $twigExtension;

    public function __construct(SourceCodeExtension $twigExtension)
    {
        $this->twigExtension = $twigExtension;
    }

    public function registerCurrentController(FilterControllerEvent $event)
    {
        // this check is needed because in Symfony a request can perform any
        // number of sub-requests. See
        // http://symfony.com/doc/current/components/http_kernel/introduction.html#sub-requests
        if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
            $this->twigExtension->setController($event->getController());
        }
    }
}<commit_msg>minor #70 Improve the checking if the current request is a master request in the ControllerListener. (voronkovich)<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 AppBundle\EventListener;

use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use AppBundle\Twig\SourceCodeExtension;

/**
 * Defines the method that 'listens' to the 'kernel.controller' event, which is
 * triggered whenever a controller is executed in the application.
 * See http://symfony.com/doc/current/book/internals.html#kernel-controller-event
 *
 * Tip: listeners are common in Symfony applications, but this particular listener
 * is too advanced and too specific for the demo application needs. For more common
 * examples see http://symfony.com/doc/current/cookbook/service_container/event_listener.html
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ControllerListener
{
    protected $twigExtension;

    public function __construct(SourceCodeExtension $twigExtension)
    {
        $this->twigExtension = $twigExtension;
    }

    public function registerCurrentController(FilterControllerEvent $event)
    {
        // this check is needed because in Symfony a request can perform any
        // number of sub-requests. See
        // http://symfony.com/doc/current/components/http_kernel/introduction.html#sub-requests
        if ($event->isMasterRequest()) {
            $this->twigExtension->setController($event->getController());
        }
    }
}
{'fraction_non_alphanumeric': 0.100181598062954, 'fraction_numerical': 0.0006053268765133172, 'mean_word_length': 3.853157121879589, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, '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': '3948999', 'n_tokens_mistral': 878, 'n_tokens_neox': 868, 'n_words': 273}