src/Loops/Service/WebCore.php
private function resolvePage($url, $processing = []) {
        $path = ltrim($url, "/");
        $routes = self::getRoutes($this->getLoops());

        foreach($routes as $route => $pageclass) {
            $regexp = "/^".str_replace("\*", "([^\/]+)", preg_quote($route, "/"))."/";

            if(!preg_match($regexp, $path, $match)) {
                continue;
            }

            $page_parameter = array_slice($match, 1);

            //check if regexp conditions are defined via annotations
            if($page_parameter) {
                $reqs = $this->getLoops()->getService("annotations")->get($pageclass)->find("PageParameter");

                foreach($page_parameter as $parameter) {
                    if($req = array_pop($reqs)) {
                        if($req->regexp) {
                            if(!preg_match($req->regexp, $parameter)) {
                                continue 2;
                            }
                        }

                        if(is_array($req->allow)) {
                            if(!in_array($parameter, $req->allow)) {
                                continue 2;
                            }
                        }

                        if(is_array($req->exclude)) {
                            if(in_array($parameter, $req->exclude)) {
                                continue 2;
                            }
                        }

                        if($req->callback) {
                            if(!call_user_func([$pageclass, $req->callback], $parameter)) {
                                continue 2;
                            }
                        }
                    }
                }
            }

            $parameter = ltrim(substr($path, strlen($match[0])), "/");
            $parameter = strlen($parameter) ? array_values(explode("/", $parameter)) : [];

            yield [ $pageclass, $page_parameter, $parameter ];
        }
    }
private function resolvePage($url, $processing = []) {
        $path = ltrim($url, "/");
        $routes = self::getRoutes($this->getLoops());

        foreach($routes as $route => $pageclass) {
            $regexp = "/^".str_replace("\*", "([^\/]+)", preg_quote($route, "/"))."/";

            if(!preg_match($regexp, $path, $match)) {
                continue;
            }

            $page_parameter = array_slice($match, 1);

            //check if regexp conditions are defined via annotations
            if($page_parameter) {
                $reqs = $this->getLoops()->getService("annotations")->get($pageclass)->find("PageParameter");

                foreach($page_parameter as $parameter) {
                    if($req = array_pop($reqs)) {
                        if($req->regexp) {
                            if(!preg_match($req->regexp, $parameter)) {
                                continue 2;
                            }
                        }

                        if(is_array($req->allow)) {
                            if(!in_array($parameter, $req->allow)) {
                                continue 2;
                            }
                        }

                        if(is_array($req->exclude)) {
                            if(in_array($parameter, $req->exclude)) {
                                continue 2;
                            }
                        }

                        if($req->callback) {
                            if(!call_user_func([$pageclass, $req->callback], $parameter)) {
                                continue 2;
                            }
                        }
                    }
                }
            }

            $parameter = ltrim(substr($path, strlen($match[0])), "/");
            $parameter = strlen($parameter) ? array_values(explode("/", $parameter)) : [];

            yield [ $pageclass, $page_parameter, $parameter ];
        }
    }
private function resolvePage ( $ url , $ processing = [ ] ) { $ path = ltrim ( $ url , "/" ) ; $ routes = self :: getRoutes ( $ this -> getLoops ( ) ) ; foreach ( $ routes as $ route => $ pageclass ) { $ regexp = "/^" . str_replace ( "\*" , "([^\/]+)" , preg_quote ( $ route , "/" ) ) . "/" ; if ( ! preg_match ( $ regexp , $ path , $ match ) ) { continue ; } $ page_parameter = array_slice ( $ match , 1 ) ; //check if regexp conditions are defined via annotations if ( $ page_parameter ) { $ reqs = $ this -> getLoops ( ) -> getService ( "annotations" ) -> get ( $ pageclass ) -> find ( "PageParameter" ) ; foreach ( $ page_parameter as $ parameter ) { if ( $ req = array_pop ( $ reqs ) ) { if ( $ req -> regexp ) { if ( ! preg_match ( $ req -> regexp , $ parameter ) ) { continue 2 ; } } if ( is_array ( $ req -> allow ) ) { if ( ! in_array ( $ parameter , $ req -> allow ) ) { continue 2 ; } } if ( is_array ( $ req -> exclude ) ) { if ( in_array ( $ parameter , $ req -> exclude ) ) { continue 2 ; } } if ( $ req -> callback ) { if ( ! call_user_func ( [ $ pageclass , $ req -> callback ] , $ parameter ) ) { continue 2 ; } } } } } $ parameter = ltrim ( substr ( $ path , strlen ( $ match [ 0 ] ) ) , "/" ) ; $ parameter = strlen ( $ parameter ) ? array_values ( explode ( "/" , $ parameter ) ) : [ ] ; yield [ $ pageclass , $ page_parameter , $ parameter ] ; } }
Find the page object that should be displayed based on the accessed url

This method will resolve the url to a page class. It will try to find and autoload
the class with the same name as the url (including namespaces) inside the "Pages" namespace.
The first letter of every part of the url is capitalized to honor the loops coding standard.
Ex: 'subdir/deep/deeper/myclass' -> "Pages\Subdir\Deep\Deeper\Myclass"

A trailing '/' in the url tells loops to look for a class named 'Index' inside that namespace.
Ex: 'subdir/deep/deeper/myclass/' -> 'Pages\Subdir\Deep\Deeper\Myclass\Index'

If no class with that name is found, less deep namespaces will be searched for appropriate classes
or Index classes.
The above url ('/subdir/deep/deeper/myclass/') will search for page classes in the following order:
- Pages\Subdir\Deep\Deeper\Myclass\Index
- Pages\Subdir\Deep\Deeper\Myclass
- Pages\Subdir\Deep\Deeper\Index
- Pages\Subdir\Deep\Deeper
- Pages\Subdir\Deep\Index
- Pages\Subdir\Deep
- Pages\Subdir\Index
- Pages\Subdir
- Pages\Index

All parts of the url that are not part of the classname will be saved in an array as parameters.
These parameters will be divided into 'page parameter' and 'action parameter'.
If the classname contains namespaces called '_' (a single underbar namespace), the first n parameters will be used as page parameters with n being the number of such namespaces.
If the classname is called '_' another parameter will be used as page parameter.
These parameters will be passed to the page class constructor.
The remaining parameters, if any, will be passed to the action method of that page class while dispatching the request.

The classes must be non abstract or they will be taken into account. You can make a page class abstract if other
pages inherit from it but should not be displayed directly.
Find the page object that should be displayed based on the accessed url