src/Loops/Service/WebCore.php
private static function getRoutes($loops) {
        $cache = $loops->getService("cache");
        $key = "Loops-WebCore-getRoutes";

        if($cache->contains($key)) {
            return $cache->fetch($key);
        }

        if(!$loops->hasService("application")) {
            return FALSE;
        }

        $classnames = $loops->getService("application")->definedClasses();

        $classnames = array_filter($classnames, function($classname) {
            return substr($classname, 0, 6) == "Pages\\";
        });

        $routes = [];

        foreach($classnames as $classname) {
            if(!in_array("Loops\ElementInterface", class_implements($classname))) {
                continue;
            }

            if(!$classname::isPage()) {
                continue;
            }

            $reflection = new ReflectionClass($classname);
            if($reflection->isAbstract()) {
                continue;
            }

            if(substr($reflection->getFileName(), -strlen($classname)-4, strlen($classname)) != str_replace("\\", "/", $classname)) {
                continue;
            }

            $classbase = substr(str_replace("\\", "/", strtolower($classname)), 5);

            if(substr($classbase, -6) == "/index") {
                $classbase = substr($classbase, 0, -5);
            }

            $routes[str_replace("_", "*", substr($classbase, 1))] = $classname;
        }

        uksort($routes, function($a, $b) {
            return substr_count($b, "/") - substr_count($a, "/") ?: strlen($b) - strlen($a);
        });

        $cache->save($key, $routes);

        return $routes;
    }
private static function getRoutes($loops) {
        $cache = $loops->getService("cache");
        $key = "Loops-WebCore-getRoutes";

        if($cache->contains($key)) {
            return $cache->fetch($key);
        }

        if(!$loops->hasService("application")) {
            return FALSE;
        }

        $classnames = $loops->getService("application")->definedClasses();

        $classnames = array_filter($classnames, function($classname) {
            return substr($classname, 0, 6) == "Pages\\";
        });

        $routes = [];

        foreach($classnames as $classname) {
            if(!in_array("Loops\ElementInterface", class_implements($classname))) {
                continue;
            }

            if(!$classname::isPage()) {
                continue;
            }

            $reflection = new ReflectionClass($classname);
            if($reflection->isAbstract()) {
                continue;
            }

            if(substr($reflection->getFileName(), -strlen($classname)-4, strlen($classname)) != str_replace("\\", "/", $classname)) {
                continue;
            }

            $classbase = substr(str_replace("\\", "/", strtolower($classname)), 5);

            if(substr($classbase, -6) == "/index") {
                $classbase = substr($classbase, 0, -5);
            }

            $routes[str_replace("_", "*", substr($classbase, 1))] = $classname;
        }

        uksort($routes, function($a, $b) {
            return substr_count($b, "/") - substr_count($a, "/") ?: strlen($b) - strlen($a);
        });

        $cache->save($key, $routes);

        return $routes;
    }
private static function getRoutes ( $ loops ) { $ cache = $ loops -> getService ( "cache" ) ; $ key = "Loops-WebCore-getRoutes" ; if ( $ cache -> contains ( $ key ) ) { return $ cache -> fetch ( $ key ) ; } if ( ! $ loops -> hasService ( "application" ) ) { return FALSE ; } $ classnames = $ loops -> getService ( "application" ) -> definedClasses ( ) ; $ classnames = array_filter ( $ classnames , function ( $ classname ) { return substr ( $ classname , 0 , 6 ) == "Pages\\" ; } ) ; $ routes = [ ] ; foreach ( $ classnames as $ classname ) { if ( ! in_array ( "Loops\ElementInterface" , class_implements ( $ classname ) ) ) { continue ; } if ( ! $ classname :: isPage ( ) ) { continue ; } $ reflection = new ReflectionClass ( $ classname ) ; if ( $ reflection -> isAbstract ( ) ) { continue ; } if ( substr ( $ reflection -> getFileName ( ) , - strlen ( $ classname ) - 4 , strlen ( $ classname ) ) != str_replace ( "\\" , "/" , $ classname ) ) { continue ; } $ classbase = substr ( str_replace ( "\\" , "/" , strtolower ( $ classname ) ) , 5 ) ; if ( substr ( $ classbase , - 6 ) == "/index" ) { $ classbase = substr ( $ classbase , 0 , - 5 ) ; } $ routes [ str_replace ( "_" , "*" , substr ( $ classbase , 1 ) ) ] = $ classname ; } uksort ( $ routes , function ( $ a , $ b ) { return substr_count ( $ b , "/" ) - substr_count ( $ a , "/" ) ? : strlen ( $ b ) - strlen ( $ a ) ; } ) ; $ cache -> save ( $ key , $ routes ) ; return $ routes ; }
Generates an array with all available routes
Generates an array with all available routes