<commit_before><?php
/**
 *
 */

namespace Mvc5\Url;

use Mvc5\Arg;
use Mvc5\Http\Uri;

class Plugin
{
    /**
     * @var callable
     */
    protected $generator;

    /**
     * @var string
     */
    protected $name;

    /**
     * @var array
     */
    protected $params;

    /**
     * @param array|\ArrayAccess $request
     * @param callable $generator
     * @param callable $assembler
     */
    function __construct($request, callable $generator, callable $assembler = null)
    {
        $this->assembler = $assembler ?: new Assemble;
        $this->generator = $generator;
        $this->name      = $request[Arg::NAME];
        $this->params    = (array) $request[Arg::PARAMS];
    }

    /**
     * @param string|Uri $route
     * @param array|string $query
     * @param string $fragment
     * @param array $options
     * @return mixed
     */
    protected function assemble($route, $query = '', $fragment = '', array $options = [])
    {
        return $route ? ($this->assembler)($route, $query, $fragment, $options) : null;
    }

    /**
     * @param array|string $route
     * @param array|string $query
     * @param string $fragment
     * @param array $options
     * @return Uri
     */
    protected function create($route, $query, $fragment, $options)
    {
        return $this->assemble($this->route((array) $route, $this->options($query, $fragment, $options))) ?:
            $this->assemble($route, $query, $fragment, $options);
    }

    /**
     * @param string $name
     * @param array $params
     * @param array $options
     * @return Uri
     */
    protected function generate($name, $params, $options)
    {
        return ($this->generator)($this->name($name), $this->params($name, $params), $options);
    }

    /**
     * @param string $name
     * @return string
     */
    protected function name($name)
    {
        return $name ?? $this->name;
    }

    /**
     * @param string $query
     * @param string $fragment
     * @param array $options
     * @return array
     */
    protected function options($query, $fragment, array $options = [])
    {
        return [Arg::FRAGMENT => $fragment, Arg::QUERY => $query] + $options;
    }

    /**
     * @param string $name
     * @param array $params
     * @return array
     */
    protected function params($name, array $params)
    {
        return $name ? $params : $params + $this->params;
    }

    /**
     * @param array $route
     * @param array $options
     * @return Uri|null
     */
    protected function route(array $route, $options)
    {
        return $this->generate(array_shift($route), $route, $options);
    }

    /**
     * @param array|string $route
     * @param array|string $query
     * @param string $fragment
     * @param array $options
     * @return string
     */
    function __invoke($route = null, $query = '', $fragment = '', array $options = [])
    {
        return $route instanceof Uri ? $this->assemble($route) : $this->create($route, $query, $fragment, $options);
    }
}
<commit_msg>skip generator if forward slash<commit_after><?php
/**
 *
 */

namespace Mvc5\Url;

use Mvc5\Arg;
use Mvc5\Http\Uri;

class Plugin
{
    /**
     * @var callable
     */
    protected $generator;

    /**
     * @var string
     */
    protected $name;

    /**
     * @var array
     */
    protected $params;

    /**
     * @param array|\ArrayAccess $request
     * @param callable $generator
     * @param callable $assembler
     */
    function __construct($request, callable $generator, callable $assembler = null)
    {
        $this->assembler = $assembler ?: new Assemble;
        $this->generator = $generator;
        $this->name      = $request[Arg::NAME];
        $this->params    = (array) $request[Arg::PARAMS];
    }

    /**
     * @param string|Uri $route
     * @param array|string $query
     * @param string $fragment
     * @param array $options
     * @return mixed
     */
    protected function assemble($route, $query = '', $fragment = '', array $options = [])
    {
        return $route ? ($this->assembler)($route, $query, $fragment, $options) : null;
    }

    /**
     * @param array|string $route
     * @param array|string $query
     * @param string $fragment
     * @param array $options
     * @return Uri
     */
    protected function create($route, $query, $fragment, $options)
    {
        return $this->assemble($this->route((array) $route, $this->options($query, $fragment, $options))) ?:
            $this->assemble($route, $query, $fragment, $options);
    }

    /**
     * @param string $name
     * @param array $params
     * @param array $options
     * @return Uri
     */
    protected function generate($name, $params, $options)
    {
        return $name[0] !== Arg::SEPARATOR ? ($this->generator)($name, $this->params($name, $params), $options) : null;
    }

    /**
     * @param string $name
     * @return string
     */
    protected function name($name)
    {
        return (string) ($name ?: $this->name);
    }

    /**
     * @param string $query
     * @param string $fragment
     * @param array $options
     * @return array
     */
    protected function options($query, $fragment, array $options = [])
    {
        return [Arg::FRAGMENT => $fragment, Arg::QUERY => $query] + $options;
    }

    /**
     * @param string $name
     * @param array $params
     * @return array
     */
    protected function params($name, array $params)
    {
        return $name === $this->name ? $params + $this->params : $params;
    }

    /**
     * @param array $route
     * @param array $options
     * @return Uri|null
     */
    protected function route(array $route, $options)
    {
        return $this->generate($this->name(array_shift($route)), $route, $options);
    }

    /**
     * @param array|string $route
     * @param array|string $query
     * @param string $fragment
     * @param array $options
     * @return string
     */
    function __invoke($route = null, $query = '', $fragment = '', array $options = [])
    {
        return $route instanceof Uri ? $this->assemble($route) : $this->create($route, $query, $fragment, $options);
    }
}

{'fraction_non_alphanumeric': 0.15980551053484604, 'fraction_numerical': 0.00113452188006483, 'mean_word_length': 2.27027027027027, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, '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': '1157516', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1866, 'n_words': 461}