<commit_before><?php

namespace MFB\RedirectBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

/**
 * Menu controller
 */
class RedirectController extends Controller
{
    public function extraRouteAction()
    {
        /**
         * @var \Symfony\Component\HttpFoundation\Request   $request
         * @var \MFB\RedirectBundle\Service\RedirectService $redirectService
         */
        $request = $this->get('request');
        $redirectService = $this->get('mfb_redirect.service.redirect');
        $url = $request->getRequestUri();
        $targetUrl = $redirectService->getTarget($url);

        // 301 Moved Permanently
        return new RedirectResponse($targetUrl, 301);
    }

}<commit_msg>Added 404 exception if URL couldnt be loaded from DB.<commit_after><?php

namespace MFB\RedirectBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

/**
 * Menu controller
 */
class RedirectController extends Controller
{
    public function extraRouteAction()
    {
        /**
         * @var \Symfony\Component\HttpFoundation\Request   $request
         * @var \MFB\RedirectBundle\Service\RedirectService $redirectService
         */
        $request = $this->get('request');
        $redirectService = $this->get('mfb_redirect.service.redirect');
        $url = $request->getRequestUri();
        $targetUrl = $redirectService->getTarget($url);

        // @todo log URL to find out where empty strings come from
        if (empty($targetUrl)) {
            throw new NotFoundHttpException();
        }

        // 301 Moved Permanently
        return new RedirectResponse($targetUrl, 301);
    }

}
{'fraction_non_alphanumeric': 0.10575296108291032, 'fraction_numerical': 0.006345177664974619, 'mean_word_length': 3.7585513078470827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5428579', 'n_tokens_mistral': 633, 'n_tokens_neox': 615, 'n_words': 119}