<commit_before><?php

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

namespace Dunglas\JsonLdApiBundle\Routing;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouterInterface;

/**
 * Router decorator.
 *
 * <NAME> <<EMAIL>>
 */
class Router implements RouterInterface
{
    /**
     * @var RouterInterface
     */
    private $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    /**
     * {@inheritdoc}
     */
    public function setContext(RequestContext $context)
    {
        $this->router->setContext($context);
    }

    /**
     * {@inheritdoc}
     */
    public function getContext()
    {
        $this->router->getContext();
    }

    /**
     * {@inheritdoc}
     */
    public function getRouteCollection()
    {
        $this->router->getRouteCollection();
    }

    /*
     * {@inheritdoc}
     */
    public function match($pathinfo)
    {
        $request = Request::create($pathinfo);
        $context = (new RequestContext())->fromRequest($request);
        $baseContext = $this->router->getContext();

        try {
            $this->router->setContext($context);

            return $this->router->match($request->getPathInfo());
        } finally {
            $this->router->setContext($baseContext);
        }
    }

    /*
     * {@inheritdoc}
     */
    public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
    {
        $hasGenerator = method_exists($this->router, 'getGenerator');

        if ($hasGenerator) {
            $baseContext = $this->router->getGenerator()->getContext();
            $request = Request::create('');
            $context = (new RequestContext())->fromRequest($request);
            $context->setHost($baseContext->getHost());
            $context->setScheme($baseContext->getScheme());
            $context->setHttpPort($baseContext->getHttpPort());
            $context->setHttpsPort($baseContext->getHttpsPort());
            $context->setBaseUrl('');
            $this->router->getGenerator()->setContext($context);
        }

        try {
            return $this->router->generate($name, $parameters, $referenceType);
        } finally {
            if ($hasGenerator) {
                $this->router->getGenerator()->setContext($baseContext);
            }<commit_msg>Optimize Router decorator<commit_after><?php

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

namespace Dunglas\JsonLdApiBundle\Routing;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouterInterface;

/**
 * Router decorator.
 *
 * <NAME> <<EMAIL>>
 */
class Router implements RouterInterface
{
    /**
     * @var RouterInterface
     */
    private $router;

    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }

    /**
     * {@inheritdoc}
     */
    public function setContext(RequestContext $context)
    {
        $this->router->setContext($context);
    }

    /**
     * {@inheritdoc}
     */
    public function getContext()
    {
        $this->router->getContext();
    }

    /**
     * {@inheritdoc}
     */
    public function getRouteCollection()
    {
        $this->router->getRouteCollection();
    }

    /*
     * {@inheritdoc}
     */
    public function match($pathInfo)
    {
        $baseContext = $this->router->getContext();

        $request = Request::create($pathInfo);
        $context = (new RequestContext())->fromRequest($request);
        $context->setPathInfo($pathInfo);

        try {
            $this->router->setContext($context);

            return $this->router->match($request->getPathInfo());
        } finally {
            $this->router->setContext($baseContext);
        }
    }

    /*
     * {@inheritdoc}
     */
    public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
    {
        $baseContext = $this->router->getContext();
        try {
            $this->router->setContext(new RequestContext(
                '',
                'GET',
                $baseContext->getHost(),
                $baseContext->getScheme(),
                $baseContext->getHttpPort(),
                $baseContext->getHttpsPort()
            ));

            return $this->router->generate($name, $parameters, $referenceType);
        } finally {
            $this->router->setContext($baseContext);
{'fraction_non_alphanumeric': 0.14687756778964667, 'fraction_numerical': 0.0, 'mean_word_length': 2.328092959671907, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 84, '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': '2802340', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1333, 'n_words': 240}