<commit_before><?php

/**
 * This file is part of the Miny framework.
 * (c) <NAME> <<EMAIL>>
 *
 * For licensing information see the LICENCE file.
 */

namespace Modules\Templating\Extensions;

use Miny\Application\Application;
use Miny\Application\Dispatcher;
use Miny\Routing\Router;
use Modules\Templating\Compiler\Functions\MethodFunction;
use Modules\Templating\Compiler\Functions\SimpleFunction;
use Modules\Templating\Extension;

class Miny extends Extension
{
    /**
     * @var Application
     */
    private $application;

    /**
     * @var Dispatcher
     */
    private $dispatcher;

    /**
     * @var Router
     */
    private $router;

    /**
     * @param Application $app
     * @param Dispatcher  $dispatcher
     * @param Router      $router
     */
    public function __construct(Application $app, Dispatcher $dispatcher, Router $router)
    {
        parent::__construct();
        $this->application = $app;
        $this->dispatcher  = $dispatcher;
        $this->router      = $router;
    }

    public function getExtensionName()
    {
        return 'miny';
    }

    public function getFunctions()
    {
        $functions = array(
            new MethodFunction('route', 'routeFunction'),
            new MethodFunction('request', 'requestFunction'),
        );
        if ($this->application->isDeveloperEnvironment()) {
            $functions[] = new SimpleFunction('dump', 'var_dump');
        }

        return $functions;
    }

    public function routeFunction($route, array $parameters = array())
    {
        return $this->router->generate($route, $parameters);
    }

    public function requestFunction($url, $method = 'GET', array $post = array())
    {
        $factory = $this->application->getContainer();

        $main = $factory->get('\\Miny\\HTTP\\Response');
        $main->addContent(ob_get_clean());

        $request  = $factory->get('\\Miny\\HTTP\\Request')->getSubRequest($method, $url, $post);
        $response = $this->dispatcher->dispatch($request);

        $main->addResponse($response);
        ob_start();
    }
}<commit_msg>Update to use new components.<commit_after><?php

/**
 * This file is part of the Miny framework.
 * (c) <NAME> <<EMAIL>>
 *
 * For licensing information see the LICENCE file.
 */

namespace Modules\Templating\Extensions;

use Miny\Application\Application;
use Miny\Application\Dispatcher;
use Miny\Routing\RouteGenerator;
use Modules\Templating\Compiler\Functions\MethodFunction;
use Modules\Templating\Compiler\Functions\SimpleFunction;
use Modules\Templating\Extension;

class Miny extends Extension
{
    /**
     * @var Application
     */
    private $application;

    /**
     * @var Dispatcher
     */
    private $dispatcher;

    /**
     * @var RouteGenerator
     */
    private $routeGenerator;

    /**
     * @param Application    $app
     * @param Dispatcher     $dispatcher
     * @param RouteGenerator $routeGenerator
     */
    public function __construct(
        Application $app,
        Dispatcher $dispatcher,
        RouteGenerator $routeGenerator
    ) {
        parent::__construct();
        $this->application    = $app;
        $this->dispatcher     = $dispatcher;
        $this->routeGenerator = $routeGenerator;
    }

    public function getExtensionName()
    {
        return 'miny';
    }

    public function getFunctions()
    {
        $functions = array(
            new MethodFunction('route', 'routeFunction'),
            new MethodFunction('request', 'requestFunction'),
        );
        if ($this->application->isDeveloperEnvironment()) {
            $functions[] = new SimpleFunction('dump', 'var_dump');
        }

        return $functions;
    }

    public function routeFunction($route, array $parameters = array())
    {
        return $this->routeGenerator->generate($route, $parameters);
    }

    public function requestFunction($url, $method = 'GET', array $post = array())
    {
        $container = $this->application->getContainer();

        $main = $container->get('\\Miny\\HTTP\\Response');
        $main->addContent(ob_get_clean());

        $request  = $container->get('\\Miny\\HTTP\\Request')->getSubRequest($method, $url, $post);
        $response = $this->dispatcher->dispatch($request);

        $main->addResponse($response);
        ob_start();
    }
}
{'fraction_non_alphanumeric': 0.13754045307443366, 'fraction_numerical': 0.0, 'mean_word_length': 2.6118530884808013, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6779628', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1187, 'n_words': 259}