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

namespace Mvc5\Route\Match;

use Mvc5\Arg;
use Mvc5\Route\Route;
use Mvc5\Route\Request;

class Path
{
    /**
     * @param array $map
     * @param array $matches
     * @param array $defaults
     * @return array
     */
    protected function params(array $map, array $matches, array $defaults = [])
    {
        $matched = [];

        foreach($map as $name => $arg) {
            !empty($matches[$name]) && $matched[$arg] = $matches[$name];
        }

        return $matched + $defaults;
    }

    /**
     * @param Request $request
     * @param Route $route
     * @return Request
     */
    function __invoke(Request $request, Route $route)
    {
        if (!preg_match('(\G' . $route->regex() . ')', $request->path(), $matches, null, $request->length())) {
            return null;
        }

        $request[Arg::CONTROLLER] = $route->controller();
        $request[Arg::LENGTH]     = $request->length() + strlen($matches[0]);
        $request[Arg::MATCHED]    = $request->length() == strlen($request->path());
        $request[Arg::PARAMS]     = $this->params($route->map(), $matches, $route->defaults());

        return $request;
    }
}<commit_msg>partial match with child routes stops current match event<commit_after><?php
/**
 *
 */

namespace Mvc5\Route\Match;

use Mvc5\Arg;
use Mvc5\Event\Event;
use Mvc5\Route\Route;
use Mvc5\Route\Request;

class Path
{
    /**
     * @param array $map
     * @param array $matches
     * @param array $defaults
     * @return array
     */
    protected function params(array $map, array $matches, array $defaults = [])
    {
        $matched = [];

        foreach($map as $name => $arg) {
            !empty($matches[$name]) && $matched[$arg] = $matches[$name];
        }

        return $matched + $defaults;
    }

    /**
     * @param Event $event
     * @param Request $request
     * @param Route $route
     * @return Request
     */
    function __invoke(Event $event, Request $request, Route $route)
    {
        if (!preg_match('(\G' . $route->regex() . ')', $request->path(), $matches, null, $request->length())) {
            return null;
        }

        $request[Arg::CONTROLLER] = $route->controller();
        $request[Arg::LENGTH]     = $request->length() + strlen($matches[0]);
        $request[Arg::MATCHED]    = $request->length() == strlen($request->path());
        $request[Arg::PARAMS]     = $this->params($route->map(), $matches, $route->defaults());

        return $request->matched() || ($route->children() && $event->stop()) ? $request : null;
    }
}
{'fraction_non_alphanumeric': 0.1855151045701007, 'fraction_numerical': 0.004260263361735089, 'mean_word_length': 2.48582995951417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '3067396', 'n_tokens_mistral': 803, 'n_tokens_neox': 791, 'n_words': 173}