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

matchDefaultMethod() private method

This is the fallback method that tries to match a default method.
private matchDefaultMethod ( array $callbacks, string $url, $classUrl ) : array
$callbacks array Available callbacks in the current class.
$url string Url upon we will do the match
return array
    private function matchDefaultMethod($callbacks, $url, $classUrl)
    {
        // match a callback based on url pattern
        $methodData = false;
        $matchedParameters = false;
        // match method
        foreach ($callbacks as $pattern => $data) {
            if ($data['default'] !== false && $data['resourceNaming'] === false) {
                // for default method we need to remove the method name from the pattern
                $methodUrl = $data['method'];
                if ($this->normalize) {
                    $methodUrl = PathTransformations::methodNameToUrl($methodUrl);
                }
                $pattern = $classUrl . '/' . str_replace($methodUrl . '/', '', $pattern);
                if (($matchedParameters = $this->doesPatternMatch($pattern, $data, $url)) !== false) {
                    $methodData = $data;
                    break;
                } else {
                    $methodName = $data['method'];
                    $data['method'] = $classUrl;
                    $matchedParameters = $this->tryMatchingOptionalParams($pattern, $data, $url);
                    $data['method'] = $methodName;
                    if ($matchedParameters) {
                        $methodData = $data;
                        break;
                    }
                }
            }
        }
        return ['methodData' => $methodData, 'matchedParameters' => $matchedParameters];
    }