Webiny\Component\Rest\Response\Router::tryMatchingOptionalParams PHP Method

tryMatchingOptionalParams() private method

Note: this works only with standard urls and not with resource naming
private tryMatchingOptionalParams ( string $pattern, array $data, string $url ) : boolean
$pattern string Pattern that will be used for matching.
$data array An array holding the information about the parameters.
$url string Url upon we will try to do the match.
return boolean True is returned if $pattern matches $url, otherwise false.
    private function tryMatchingOptionalParams($pattern, $data, $url)
    {
        // first we check if we have any default params
        $hasDefaultParams = false;
        foreach ($data['params'] as $p) {
            if (!is_null($p['default'])) {
                $hasDefaultParams = true;
            }
        }
        if (!$hasDefaultParams) {
            return false;
        }
        // get parameters that we already have in the url
        $methodUrlName = $data['method'];
        if ($this->normalize) {
            $methodUrlName = PathTransformations::methodNameToUrl($methodUrlName);
        }
        $urlParts = explode('/', $url);
        $numIncludedParams = count($urlParts) - (array_search($methodUrlName, $urlParts) + 2);
        $numAddedParams = 0;
        $requiredParamNum = count($data['params']);
        $loopIndex = 0;
        foreach ($data['params'] as $p) {
            if ($loopIndex >= $numIncludedParams) {
                if (!is_null($p['default'])) {
                    $url .= $p['default'] . '/';
                    $numAddedParams++;
                }
            }
            $loopIndex++;
        }
        if ($numIncludedParams + $numAddedParams != $requiredParamNum) {
            return false;
        }
        return $this->doesPatternMatch($pattern, $data, $url);
    }