Register a parameter name with validation from route uri.

@param string $uri
@param bool $isGroup

@return mixed
509424
protected function namedParameters($uri, $isGroup = false)
    {
        // Reset pattern and parameters to empty array.
        $this->patt = [];
        $this->prams = [];

        // Replace named parameters to regex pattern.
        return preg_replace_callback('/\/\{([a-z-0-9]+)\}\??(:\(?[^\/]+\)?)?/i', function ($m) use ($isGroup) {
            // Check whether validation has been set and whether it exists.
            if (isset($m[2])) {
                $rep = substr($m[2], 1);
                $patt = isset($this->pattern[$rep]) ? $this->pattern[$rep] : '/' . $rep;
            } else {
                $patt = $this->pattern['/?'];
            }
            // Check whether parameter is optional.
            if (strpos($m[0], '?') !== false) {
                $patt = str_replace('/(', '(/', $patt) . '?';
            }

            if ($isGroup) {
                $this->isGroup = true;
                $this->pramsGroup[] = $m[1];
                $this->pattGroup[] = $patt;
            } else {
                $this->prams[] = $m[1];
                $this->patt[] = $patt;
            }

            return $patt;
        }, trim($uri));
    }
1211720
public function add($uri, $method, $controller, $action) {
        $this->currentRoute = [
            'uri' => $uri,
            'method' => $method,
            'controller' => $controller,
            'action' => $action,
            'module' => $this->module,
        ];

        if ($this->currentGroupName) {
            $this->virtualRoutes[$this->currentGroupName][] = $this->currentRoute;
        } else {
            $this->virtualRoutes['*'][] = $this->currentRoute;
        }

        return $this;
    }
1003181
public function internalRedirect($uri)
    {
        if (is_string($uri)) {

            // make a new URI instance, then make a new request
            $uri = $this->request->getUri()->withPath($uri);
            return $this->request->withUri($uri);

        } elseif ($uri instanceof UriInterface) {

            // get a new request with the specified URI instance
            return $this->request->withUri($uri);

        } else {

            // bad $uri value
            throw new InvalidArgumentException(
                'URI should be a string or instance of Psr\Http\Message\UriInterface'
            );

        }
    }
508100
private function match(string $uri, string $routeUri): ?array
    {
        if ($uri === $routeUri) {
            return [];
        }

        return $this->getArguments($uri, $routeUri);
    }
1247015
public static function validateURI($uri) {
        if(!empty(trim($uri))){
            return filter_var(trim($uri), FILTER_VALIDATE_URL);
        }
        return false;
    }
334480
private function validateUri(string $uri): void
    {
        if (filter_var($uri, FILTER_VALIDATE_URL) === false) {
            throw new InvalidArgumentException(sprintf('%s is not a valid uri', $uri));
        }
    }
1179995
public function any($uri, $action = null) {
        return $this->addRoute(Route::HTTP_METHODS, $uri, $action);
    }
338024
private function validateString(string $uri): void
    {
        if (!\is_string($uri)) {
            throw new InvalidArgumentException(sprintf('String required, %s given', \gettype($uri)));
        }
    }
102544
public function composeUrl($iSigner, $credential, $domain)
    {
        $apiParams                     = parent::getQueryParameters();
        $apiParams["RegionId"]         = $this->getRegionId();
        $apiParams["AccessKeyId"]      = $credential->getAccessKeyId();
        $apiParams["Format"]           = $this->getAcceptFormat();
        $apiParams["SignatureMethod"]  = $iSigner->getSignatureMethod();
        $apiParams["SignatureVersion"] = $iSigner->getSignatureVersion();
        $apiParams["SignatureNonce"]   = uniqid();
        date_default_timezone_set("GMT");
        $apiParams["Timestamp"] = date($this->dateTimeFormat);
        $apiParams["Action"]    = $this->getActionName();
        $apiParams["Version"]   = $this->getVersion();
        $apiParams["Signature"] = $this->computeSignature($apiParams, $credential->getAccessSecret(), $iSigner);
        $requestUrl             = $this->getProtocol() . "://" . $domain . "/?";

        foreach ($apiParams as $apiParamKey => $apiParamValue) {
            $requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&";
        }

        return substr($requestUrl, 0, -1);
    }
1257312
public function registerCard(string $urlReturn = null)
    {
        if ($this->exists) {
            return $this->service->registerCard($this->getId(), $urlReturn);
        }
        return false;
    }
1374030
private function getArguments(string $uri, string $routeUri): ?array
    {
        if (preg_match_all('/({[a-z]+:)/i', $routeUri, $matches)) {
            $regex = str_replace('/', '\/',
                str_replace('}', ')',
                    preg_replace('/{([a-z]+):/i', '(?<$1>', $routeUri)
                )
            );

            return $this->matchUri($regex, $uri);
        }

        return null;
    }
7082
public static function renderUri( $uri, $options = array() )
    {
        $serviceContainer = ezpKernel::instance()->getServiceContainer();
        $fragmentHandler = $serviceContainer->get( 'fragment.handler' );

        $strategy = isset( $options['strategy'] ) ? $options['strategy'] : 'inline';
        unset( $options['strategy'] );

        try
        {
            return $fragmentHandler->render( $uri, $strategy, $options );
        }
        catch ( InvalidArgumentException $e )
        {
            throw new InvalidArgumentException( "The URI {$uri->controller} couldn't be rendered", 0, $e );
        }
    }
207447
public function any($methods, $uri, $action = null)
    {
        return $this->addRoute(array_map('strtoupper', (array)$methods), $uri, $action);
    }
129270
private function registerRoute(string $className, array $routes, string $prefix, bool $coroutine, $server)
    {
        foreach ($routes as $route) {
            $mappedName = $route['mappedName'];
            $methodName = $route['methodName'];
            if (empty($mappedName)) {
                $mappedName = $methodName;
            }

            $commandKey = $this->getCommandString($prefix, $mappedName);
            $this->routes[$commandKey] = [$className, $methodName, $coroutine, $server];
        }

        $commandKey = $this->getCommandString($prefix, $this->defaultCommand);
        $this->routes[$commandKey] = [$className, $this->defaultCommand];
    }
1356525
public function setCurrentURI($uri) {
        if(is_string($uri) && !empty(trim($uri))){
            $this->currentURI = $uri;
            $this->currentArray = Levels::getCurrent($this->navigation, $this->currentURI);
        }
        else{
            throw new InvalidArgumentException(
                '$uri must be a valid string when seting the current URI'
            );
        }
        return $this;
    }
499676
private function determineHandler($isCli, $checkParams)
    {
        // determine which handler should handle this path
        foreach ($this->getHandlers() as $handler) {
            if ($isCli !== $handler->isCliHandler()) {
                continue;
            }
            $callback = array($handler, 'isAppropriate');
            if (true === call_user_func_array($callback, $checkParams)) {
                return $handler;
            }
        }

        $config = Di::getDefault()->get('config');
        if ($isCli) {
            $errorMessage = 'No CLI handler registered.';
        } else {
            $errorMessage = ($config->isDebug()) ? 'No handler responded to the request.' : '';
        }
        throw new ResourceNotFoundException($errorMessage);
    }
148057
public function isUrl($url, $isRegex = false)
    {
        if ($isRegex) {
            return preg_match('#^'.$url.'$#', $this->getFullUrl()) === 1;
        }

        return $this->getFullUrl() == $url;
    }