File "RoutePatternMatcher.php"

Full Path: /var/www/html/back/vendor/knuckleswtf/scribe/src/Tools/RoutePatternMatcher.php
File size: 914 bytes
MIME-type: text/x-php
Charset: utf-8

<?php

namespace Knuckles\Scribe\Tools;

use Illuminate\Routing\Route;
use Illuminate\Support\Str;

class RoutePatternMatcher
{
    public static function matches(Route $route, $patterns): bool
    {
        $routeName = $route->getName();
        $routePathWithoutInitialSlash = $route->uri();
        $routePathWithInitialSlash = "/$routePathWithoutInitialSlash";
        $routeMethods = $route->methods();
        if (Str::is($patterns, $routeName)
            || Str::is($patterns, $routePathWithoutInitialSlash)
            || Str::is($patterns, $routePathWithInitialSlash)) {
            return true;
        }

        foreach ($routeMethods as $httpMethod) {
            if (Str::is($patterns, "$httpMethod $routePathWithoutInitialSlash")
                || Str::is($patterns, "$httpMethod $routePathWithInitialSlash")) {
                return true;
            }
        }

        return false;
    }
}