Esempio n. 1
0
File: Route.php Progetto: larakit/lk
 static function getRouteByUri($uri)
 {
     $uri = parse_url($uri, PHP_URL_PATH);
     $routes = [];
     foreach (\Route::getRoutes()->getRoutes() as $route) {
         $routes[$route->getUri()] = $route->getName();
     }
     krsort($routes);
     //        dd($routes);
     $uri = trim($uri, '/');
     if (!$uri) {
         return 'home';
     }
     $matched = false;
     $_m = [];
     $max = null;
     foreach ($routes as $route_uri => $name) {
         /** @var \Illuminate\Routing\Route $route */
         $route_uri = preg_replace('/\\/\\{(.*)\\?\\}/U', '*', $route_uri);
         $route_uri = preg_replace('/\\*\\*/U', '*', $route_uri);
         $route_uri = preg_replace('/\\{(.*)\\}/U', '*', $route_uri);
         //dump($route_uri . ' | ' . $matched . ' | ' . $max);
         if (\Illuminate\Support\Str::is($route_uri, $uri)) {
             $_m[] = [$name, $route_uri];
             $m = mb_substr_count($route_uri, '{');
             if (is_null($max) || !$m || $m < $max) {
                 $max = $m;
                 $matched = $name;
             }
         }
     }
     //dump($_m);
     return $matched;
 }