<commit_before><?php

/*
 * Gobline Framework
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Gobline\View\Helper\Route;

use Gobline\View\Helper\ViewHelperInterface;
use Gobline\Application\Middleware\MiddlewareDispatcher;
use Gobline\Router\UriBuilder;
use Gobline\Router\RouteData;
use Gobline\Environment\Environment;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\Response\RedirectResponse;

/**
 * @author <NAME> <<EMAIL>>
 */
class Route implements ViewHelperInterface
{
    private $environment;
    private $uriBuilder;
    private $routeData;
    private $dispatcher;
    private $activeClass = 'active';

    public function __construct(
        Environment $environment,
        UriBuilder $uriBuilder,
        MiddlewareDispatcher $dispatcher
    ) {
        $this->environment = $environment;
        $this->uriBuilder = $uriBuilder;
        $this->dispatcher = $dispatcher;
    }

    public static function getName()
    {
        return 'route';
    }

    public function __invoke($routeName)
    {
        $this->data = new Data($routeName, $this);

        return $this->data;
    }

    public function uri($language = null, $absolute = false)
    {
        $routeData = new RouteData($this->data->getName(), $this->data->getParams());

        if (!$language) {
            $language = $this->environment->getLanguage();
        }

        $uri = $this->uriBuilder->buildUri($routeData, $language);
        $uri = $this->environment->buildUri($uri, $language, $absolute);

        return $uri.$this->data->getQueryString();
    }

    public function url($language = null)
    {
        return $this->uri($language, true);
    }

    public function redirect($status = 302)
    {
        $response = new RedirectResponse($this->url(), 301);
        (new SapiEmitter())->emit($response);
        exit;
    }

    public function request($suppressErrors = false)
    {
        $uri = $this->uri();

        $originalRequest = $this->environment->getRequest();
        $originalMatchedRouteName = $this->environment->getMatchedRouteName();
        $originalMatchedRouteParams = $this->environment->getMatchedRouteParams();

        $post = $_POST;
        $_POST = [];

        $get = $_GET;
        $_GET = [];

        $request = $originalRequest
                    ->withAttribute('_isSubRequest', true)
                    ->withParsedBody([])
                    ->withQueryParams($this->data->getParams())
                    ->withUri(<commit_msg>hmvc: specify method is GET<commit_after><?php

/*
 * Gobline Framework
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Gobline\View\Helper\Route;

use Gobline\View\Helper\ViewHelperInterface;
use Gobline\Application\Middleware\MiddlewareDispatcher;
use Gobline\Router\UriBuilder;
use Gobline\Router\RouteData;
use Gobline\Environment\Environment;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\Response\RedirectResponse;

/**
 * @author <NAME> <<EMAIL>>
 */
class Route implements ViewHelperInterface
{
    private $environment;
    private $uriBuilder;
    private $routeData;
    private $dispatcher;
    private $activeClass = 'active';

    public function __construct(
        Environment $environment,
        UriBuilder $uriBuilder,
        MiddlewareDispatcher $dispatcher
    ) {
        $this->environment = $environment;
        $this->uriBuilder = $uriBuilder;
        $this->dispatcher = $dispatcher;
    }

    public static function getName()
    {
        return 'route';
    }

    public function __invoke($routeName)
    {
        $this->data = new Data($routeName, $this);

        return $this->data;
    }

    public function uri($language = null, $absolute = false)
    {
        $routeData = new RouteData($this->data->getName(), $this->data->getParams());

        if (!$language) {
            $language = $this->environment->getLanguage();
        }

        $uri = $this->uriBuilder->buildUri($routeData, $language);
        $uri = $this->environment->buildUri($uri, $language, $absolute);

        return $uri.$this->data->getQueryString();
    }

    public function url($language = null)
    {
        return $this->uri($language, true);
    }

    public function redirect($status = 302)
    {
        $response = new RedirectResponse($this->url(), 301);
        (new SapiEmitter())->emit($response);
        exit;
    }

    public function request($suppressErrors = false)
    {
        $uri = $this->uri();

        $originalRequest = $this->environment->getRequest();
        $originalMatchedRouteName = $this->environment->getMatchedRouteName();
        $originalMatchedRouteParams = $this->environment->getMatchedRouteParams();

        $post = $_POST;
        $_POST = [];

        $get = $_GET;
        $_GET = [];

        $request = $originalRequest
                    ->withMethod('GET')
                    ->withAttribute('_isSubRequest', true)
                    ->withParsedBody([])
                    ->withQueryParams($this->data->getParams())
                    ->withUri(
{'fraction_non_alphanumeric': 0.1336707911511061, 'fraction_numerical': 0.0022497187851518562, 'mean_word_length': 2.6566141192597668, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 82, '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': '4091137', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1451, 'n_words': 318}