src/Route.php
public function addMatch(string $method, string $uri, $next)
    {
        $method = strtoupper($method);

        if (!in_array($method, $this->supported_methods)) {
            throw new Exception("Method " . $method . " is not supported.");
        }

        if (!is_string($uri)) {
            throw new Exception("Uri " . $uri . " is not valid.");
        }

        if (is_callable($next)) {

            $new_match = array(
                $this->ARRAY_METHOD_KEY => $method,
                $this->ARRAY_URI_KEY => $uri,
                $this->ARRAY_CALLABLE_BOOL_KEY => true,
                $this->ARRAY_CALLABLE_KEY => $next
            );

        } elseif (is_string($next)) {

            if (file_exists($next)) {
                $new_match = array(
                    $this->ARRAY_METHOD_KEY => $method,
                    $this->ARRAY_URI_KEY => $uri,
                    $this->ARRAY_CALLABLE_BOOL_KEY => false,
                    $this->ARRAY_FILE_KEY => $next
                );

            } else {
                $dir_next = __DIR__ . "/" . $next;

                if (file_exists($dir_next)) {
                    $new_match = array(
                        $this->ARRAY_METHOD_KEY => $method,
                        $this->ARRAY_URI_KEY => $uri,
                        $this->ARRAY_CALLABLE_BOOL_KEY => false,
                        $this->ARRAY_FILE_KEY => $dir_next
                    );

                } else {

                    throw new Exception("File " . $next . " not found.");
                }
            }
        } else {
            throw new Exception("Invalid third parameter. Expecting callable or file.");
        }

        array_push($this->match_list, $new_match);
    }
public function addMatch(string $method, string $uri, $next)
    {
        $method = strtoupper($method);

        if (!in_array($method, $this->supported_methods)) {
            throw new Exception("Method " . $method . " is not supported.");
        }

        if (!is_string($uri)) {
            throw new Exception("Uri " . $uri . " is not valid.");
        }

        if (is_callable($next)) {

            $new_match = array(
                $this->ARRAY_METHOD_KEY => $method,
                $this->ARRAY_URI_KEY => $uri,
                $this->ARRAY_CALLABLE_BOOL_KEY => true,
                $this->ARRAY_CALLABLE_KEY => $next
            );

        } elseif (is_string($next)) {

            if (file_exists($next)) {
                $new_match = array(
                    $this->ARRAY_METHOD_KEY => $method,
                    $this->ARRAY_URI_KEY => $uri,
                    $this->ARRAY_CALLABLE_BOOL_KEY => false,
                    $this->ARRAY_FILE_KEY => $next
                );

            } else {
                $dir_next = __DIR__ . "/" . $next;

                if (file_exists($dir_next)) {
                    $new_match = array(
                        $this->ARRAY_METHOD_KEY => $method,
                        $this->ARRAY_URI_KEY => $uri,
                        $this->ARRAY_CALLABLE_BOOL_KEY => false,
                        $this->ARRAY_FILE_KEY => $dir_next
                    );

                } else {

                    throw new Exception("File " . $next . " not found.");
                }
            }
        } else {
            throw new Exception("Invalid third parameter. Expecting callable or file.");
        }

        array_push($this->match_list, $new_match);
    }
Add all routes by calling this method.

@param string $method is the request method.
@param string $uri is the uri to be matched.
@param string|callable $next is either a file to load or a callable function.
@throws Exception