<commit_before><?php

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

namespace Mendo\Router;

use Mendo\Http\Request\HttpRequestInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class PlaceholderRequestMatcher implements RequestMatcherInterface
{
    private $route;
    private $constraints;
    private $paramNames;
    private $paramNamesPath;

    public function __construct($route, array $constraints = [])
    {
        $this->route = (string) $route;
        if ($this->route === '') {
            throw new \InvalidArgumentException('$route cannot be empty');
        }

        $this->constraints = $constraints;
    }

    // https://github.com/codeguy/Slim/blob/master/Slim/Route.php
    public function match(HttpRequestInterface $httpRequest)
    {
        //Convert URL params into regex patterns, construct a regex for this route, init params
        $patternAsRegex = preg_replace_callback(
            '#:([\w]+)\+?#',
            array($this, 'matchesCallback'),
            str_replace(')', ')?', (string)$this->route)
        );

        if (substr($this->route, -1) === '/') {
            $patternAsRegex .= '?';
        }

        $regex = '#^' . $patternAsRegex . '$#';
        //Cache URL params' names and values if this route matches the current HTTP request
        if (!preg_match($regex, $httpRequest->getPath(), $paramValues)) {
            return false;
        }

        $params = [];

        foreach ($this->paramNames as $name) {
            if (isset($paramValues[$name])) {
                if (isset($this->paramNamesPath[$name])) {
                    $params[$name] = explode('/', urldecode($paramValues[$name]));
                } else {
                    $params[$name] = urldecode($paramValues[$name]);
                }
            }
        }

        return $params;
    }
<commit_msg>Bugfix PlaceholderRequestMatcher<commit_after><?php

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

namespace Mendo\Router;

use Mendo\Http\Request\HttpRequestInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class PlaceholderRequestMatcher implements RequestMatcherInterface
{
    private $route;
    private $constraints;
    private $paramNames;
    private $paramNamesPath;

    public function __construct($route, array $constraints = [])
    {
        $this->route = (string) $route;
        if ($this->route === '') {
            throw new \InvalidArgumentException('$route cannot be empty');
        }

        $this->constraints = $constraints;
    }

    // https://github.com/codeguy/Slim/blob/master/Slim/Route.php
    public function match(HttpRequestInterface $httpRequest)
    {
        //Convert URL params into regex patterns, construct a regex for this route, init params
        $patternAsRegex = preg_replace_callback(
            '#:([\w]+)\+?#',
            array($this, 'matchesCallback'),
            str_replace(')', ')?', (string)$this->route)
        );

        if (substr($this->route, -1) === '/') {
            $patternAsRegex .= '?';
        }

        $regex = '#^' . $patternAsRegex . '$#';
        //Cache URL params' names and values if this route matches the current HTTP request
        if (!preg_match($regex, $httpRequest->getPath(), $paramValues)) {
            return false;
        }

        $params = [];

        if ($this->paramNames) {
            foreach ($this->paramNames as $name) {
                if (isset($paramValues[$name])) {
                    if (isset($this->paramNamesPath[$name])) {
                        $params[$name] = explode('/', urldecode($paramValues[$name]));
                    } else {
                        $params[$name] = urldecode($paramValues[$name]);
                    }
                }
            }
        }

        return $params;
    }

{'fraction_non_alphanumeric': 0.14444995044598613, 'fraction_numerical': 0.0004955401387512388, 'mean_word_length': 2.1514441842310696, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 32, 'https://': 2, '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': '3725834', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1086, 'n_words': 267}