<commit_before><?php
namespace SDispatcher\Middleware;

use SDispatcher\Common\RouteOptions;
use SDispatcher\DataResponse;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouteCollection;

class PaginationListener implements EventSubscriberInterface
{
    /**
     * @var \Symfony\Component\Routing\RouteCollection
     */
    protected $routes;

    public function __construct(RouteCollection $routes)
    {
        $this->routes = $routes;
    }

    /**
     * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
     */
    public function onKernelView(GetResponseForControllerResultEvent $e)
    {
        $queryset = $e->getControllerResult();
        if (!is_array($queryset)) {
            return;
        }

        $routeName = $e->getRequest()->attributes->get('_route');
        $route = $this->routes->get($routeName);
        if (!$route || !$route->getOption(RouteOptions::WILL_PAGINGATE)) {
            return;
        }

        $interface = 'SDispatcher\\Common\\PaginatorInterface';
        $paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
        if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
            return;
        }

        /* @var \SDispatcher\Common\PaginatorInterface $paginator */
        $paginator = new $paginatorClass();
        list($headers, $data) = $paginator->paginate(
            $e->getRequest(),
            $queryset,
            0,
            $route->getOption(RouteOptions::PAGE_LIMIT),
            $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME),
            $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));

        $e->setControllerResult($data);
        $response = new DataResponse($data);
        $response->headers->add($headers);
    }

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return array(KernelEvents::VIEW => 'onKernelView');
    }
}
<commit_msg>Fixed paginator to set repsonse.<commit_after><?php
namespace SDispatcher\Middleware;

use SDispatcher\Common\RouteOptions;
use SDispatcher\DataResponse;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouteCollection;

class PaginationListener implements EventSubscriberInterface
{
    /**
     * @var \Symfony\Component\Routing\RouteCollection
     */
    protected $routes;

    public function __construct(RouteCollection $routes)
    {
        $this->routes = $routes;
    }

    /**
     * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $e
     */
    public function onKernelView(GetResponseForControllerResultEvent $e)
    {
        $queryset = $e->getControllerResult();

        $routeName = $e->getRequest()->attributes->get('_route');
        $route = $this->routes->get($routeName);
        if (!$route || !$route->getOption(RouteOptions::WILL_PAGINGATE)) {
            return;
        }

        $interface = 'SDispatcher\\Common\\PaginatorInterface';
        $paginatorClass = $route->getOption(RouteOptions::PAGINATOR_CLASS);
        if (!$paginatorClass || !is_subclass_of($paginatorClass, $interface)) {
            return;
        }

        try {
            /* @var \SDispatcher\Common\PaginatorInterface $paginator */
            $paginator = new $paginatorClass();
            list($headers, $data) = $paginator->paginate(
                $e->getRequest(),
                $queryset,
                0,
                $route->getOption(RouteOptions::PAGE_LIMIT),
                $route->getOption(RouteOptions::PAGINATED_META_CONTAINER_NAME),
                $route->getOption(RouteOptions::PAGINATED_DATA_CONTAINER_NAME));
        } catch (\InvalidArgumentException $ex) {
            list($headers, $data) = array(array(), array());
        }

        $response = new DataResponse($data);
        $response->headers->add($headers);
        $e->setResponse($response);
    }

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return array(KernelEvents::VIEW => 'onKernelView');
    }
}

{'fraction_non_alphanumeric': 0.12538906180524678, 'fraction_numerical': 0.00044464206313917296, 'mean_word_length': 2.970873786407767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '6713558', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1258, 'n_words': 185}