src/php/Router.php
public function parseRoute(string $route) : Route
    {
        # removing a leading / if necessary
        if (strpos($route, $this->delimiter) === 0){
            $route = substr($route, 1);
        }

        # split the route using the configured delimiter, throw an exception if there aren't
        # at least two parts to the route string
        $routeParts = explode($this->delimiter, $route);
        if (count($routeParts) < 2) {
            throw new Exception\IncorrectFormat($route, $this->delimiter);
        }

        $object = array_shift($routeParts);
        $method = array_shift($routeParts);
        $parameters = [];

        # loop over remaining parts of the route and build the parameters array
        $index = 0;
        while(count($routeParts) > 0){
            $name = $this->parameterNames[$index] ?? 'parameter'.$index;
            $parameters[$name] = array_shift($routeParts);
            $index++;
        }

        # Determine whether this refers to a view or a controller method. Start by disallowing both,
        # allow if we find matching rules
        $allowView       = false;
        $allowController = false;
        $viewClass       = $this->viewClassPrefix . $object . $this->viewClassSuffix;
        $controllerClass = $this->controllerClassPrefix . $object . $this->controllerClassSuffix;

        if (isset($this->objects[$object]) === false && isset($this->objects['*']) === false) {
            throw new Exception\ForbiddenObject($viewClass, $controllerClass);
        }

        # first, check if both classes exist. If neither exists, throw exception
        if (class_exists($viewClass) === false && class_exists($controllerClass) === false) {
            throw new Exception\ClassNotFound($viewClass, $controllerClass);
        }

        # if the view class exists, ensure that the method is allowed to be called
        if (class_exists($viewClass) === true) {
            if (isset($this->viewMethods[$object]) === true) {
                if (isset($this->viewMethods[$object][$method]) === true || isset($this->viewMethods[$object]['*']) === true) {
                    $allowView = true;
                }
            } elseif (isset($this->viewMethods['*']) === true) {
                if (isset($this->viewMethods['*'][$method]) === true || isset($this->viewMethods['*']['*']) === true) {
                    $allowView = true;
                }
            }
        }

        # if the controller class exists, ensure that the method is allowed to be called
        if (class_exists($controllerClass) === true) {
            if (isset($this->controllerMethods[$object]) === true) {
                if (isset($this->controllerMethods[$object][$method]) === true || isset($this->controllerMethods[$object]['*']) === true) {
                    $allowController = true;
                }
            } elseif (isset($this->controllerMethods['*']) === true) {
                if (isset($this->controllerMethods['*'][$method]) === true || isset($this->controllerMethods['*']['*']) === true) {
                    $allowController = true;
                }
            }
        }

        if ($allowController === false && $allowView === false) {
            throw new Exception\ForbiddenMethod($viewClass, $controllerClass, $method);
        }


        if (class_exists($controllerClass) === true && method_exists($controllerClass, $method) === false) {
            $allowController = false;
        }
        if (class_exists($viewClass) === true && method_exists($viewClass, $method) === false) {
            $allowView = false;
        }
        if ($allowController === false && $allowView === false) {
            throw new Exception\MethodNotFound($viewClass, $controllerClass, $method);
        }

        if ($allowController === true && $allowView === true) {
            throw new Exception\AmbiguousRequest($viewClass, $controllerClass, $method);
        }

        if ($allowView) {
            $routeObject = new Route($viewClass, $method, $parameters);
        } elseif ($allowController) {
            $routeObject = new Route($controllerClass, $method, $parameters);
        }

        return $routeObject;
    }
public function parseRoute(string $route) : Route
    {
        # removing a leading / if necessary
        if (strpos($route, $this->delimiter) === 0){
            $route = substr($route, 1);
        }

        # split the route using the configured delimiter, throw an exception if there aren't
        # at least two parts to the route string
        $routeParts = explode($this->delimiter, $route);
        if (count($routeParts) < 2) {
            throw new Exception\IncorrectFormat($route, $this->delimiter);
        }

        $object = array_shift($routeParts);
        $method = array_shift($routeParts);
        $parameters = [];

        # loop over remaining parts of the route and build the parameters array
        $index = 0;
        while(count($routeParts) > 0){
            $name = $this->parameterNames[$index] ?? 'parameter'.$index;
            $parameters[$name] = array_shift($routeParts);
            $index++;
        }

        # Determine whether this refers to a view or a controller method. Start by disallowing both,
        # allow if we find matching rules
        $allowView       = false;
        $allowController = false;
        $viewClass       = $this->viewClassPrefix . $object . $this->viewClassSuffix;
        $controllerClass = $this->controllerClassPrefix . $object . $this->controllerClassSuffix;

        if (isset($this->objects[$object]) === false && isset($this->objects['*']) === false) {
            throw new Exception\ForbiddenObject($viewClass, $controllerClass);
        }

        # first, check if both classes exist. If neither exists, throw exception
        if (class_exists($viewClass) === false && class_exists($controllerClass) === false) {
            throw new Exception\ClassNotFound($viewClass, $controllerClass);
        }

        # if the view class exists, ensure that the method is allowed to be called
        if (class_exists($viewClass) === true) {
            if (isset($this->viewMethods[$object]) === true) {
                if (isset($this->viewMethods[$object][$method]) === true || isset($this->viewMethods[$object]['*']) === true) {
                    $allowView = true;
                }
            } elseif (isset($this->viewMethods['*']) === true) {
                if (isset($this->viewMethods['*'][$method]) === true || isset($this->viewMethods['*']['*']) === true) {
                    $allowView = true;
                }
            }
        }

        # if the controller class exists, ensure that the method is allowed to be called
        if (class_exists($controllerClass) === true) {
            if (isset($this->controllerMethods[$object]) === true) {
                if (isset($this->controllerMethods[$object][$method]) === true || isset($this->controllerMethods[$object]['*']) === true) {
                    $allowController = true;
                }
            } elseif (isset($this->controllerMethods['*']) === true) {
                if (isset($this->controllerMethods['*'][$method]) === true || isset($this->controllerMethods['*']['*']) === true) {
                    $allowController = true;
                }
            }
        }

        if ($allowController === false && $allowView === false) {
            throw new Exception\ForbiddenMethod($viewClass, $controllerClass, $method);
        }


        if (class_exists($controllerClass) === true && method_exists($controllerClass, $method) === false) {
            $allowController = false;
        }
        if (class_exists($viewClass) === true && method_exists($viewClass, $method) === false) {
            $allowView = false;
        }
        if ($allowController === false && $allowView === false) {
            throw new Exception\MethodNotFound($viewClass, $controllerClass, $method);
        }

        if ($allowController === true && $allowView === true) {
            throw new Exception\AmbiguousRequest($viewClass, $controllerClass, $method);
        }

        if ($allowView) {
            $routeObject = new Route($viewClass, $method, $parameters);
        } elseif ($allowController) {
            $routeObject = new Route($controllerClass, $method, $parameters);
        }

        return $routeObject;
    }
Parses a string, determines what class and method the route should map to, and returns an
instance of Lucid\Router\Route

@return Lucid\Router\Route