public function add($route, $params = '', $methods = 'GET|HEAD', $middleware = '')
    {
        // Convert the route to a regular expression: escape forward slashes
        $route = preg_replace('/\//', '\\/', $route);
        // Convert variables e.g. {controller}
        $route = preg_replace('/\{([a-z]+)\}/', '(?P<\1>[a-z-]+)', $route);
        // Convert variables with custom regular expressions e.g. {id:\d+}
        $route = preg_replace('/\{([a-z]+):([^\}]+)\}/', '(?P<\1>\2)', $route);
        // Add start and end delimiters, and case insensitive flag
        $route = '/^'.$route.'$/i';

        //If array
        if (is_array($params)) {
            $methodArray = ['method' => $methods];
            $params = array_merge($params, $methodArray);
            $this->routes[$route] = $params;
        } elseif (is_string($params)) {
            //If string
            $param = [];
            $parts = explode('@', $params);
            $param['controller'] = $parts[0];
            $param['action'] = $parts[1];
            $param['method'] = $methods;
            if (isset($parts[2])) {
                $param['namespace'] = $parts[2];
            }
            //If middleware is set then used
            (!empty($middleware)) ? $param['middleware'] = $this->addMiddleware($middleware) : $param;
            $this->routes[$route] = $param;
        } elseif (is_callable($params)) {
            (!empty($middleware)) ? $this->routes[$route] = ['callable' => $params, 'method' => $methods, 'middleware' => $this->addMiddleware($middleware)] : $this->routes[$route] = ['callable' => $params, 'method' => $methods];
        } else {
            throw new \Exception('Wrong agruments given', 500);
        }
    }
public function add($route, $params = '', $methods = 'GET|HEAD', $middleware = '')
    {
        // Convert the route to a regular expression: escape forward slashes
        $route = preg_replace('/\//', '\\/', $route);
        // Convert variables e.g. {controller}
        $route = preg_replace('/\{([a-z]+)\}/', '(?P<\1>[a-z-]+)', $route);
        // Convert variables with custom regular expressions e.g. {id:\d+}
        $route = preg_replace('/\{([a-z]+):([^\}]+)\}/', '(?P<\1>\2)', $route);
        // Add start and end delimiters, and case insensitive flag
        $route = '/^'.$route.'$/i';

        //If array
        if (is_array($params)) {
            $methodArray = ['method' => $methods];
            $params = array_merge($params, $methodArray);
            $this->routes[$route] = $params;
        } elseif (is_string($params)) {
            //If string
            $param = [];
            $parts = explode('@', $params);
            $param['controller'] = $parts[0];
            $param['action'] = $parts[1];
            $param['method'] = $methods;
            if (isset($parts[2])) {
                $param['namespace'] = $parts[2];
            }
            //If middleware is set then used
            (!empty($middleware)) ? $param['middleware'] = $this->addMiddleware($middleware) : $param;
            $this->routes[$route] = $param;
        } elseif (is_callable($params)) {
            (!empty($middleware)) ? $this->routes[$route] = ['callable' => $params, 'method' => $methods, 'middleware' => $this->addMiddleware($middleware)] : $this->routes[$route] = ['callable' => $params, 'method' => $methods];
        } else {
            throw new \Exception('Wrong agruments given', 500);
        }
    }
public function add ( $ route , $ params = '' , $ methods = 'GET|HEAD' , $ middleware = '' ) { // Convert the route to a regular expression: escape forward slashes $ route = preg_replace ( '/\//' , '\\/' , $ route ) ; // Convert variables e.g. {controller} $ route = preg_replace ( '/\{([a-z]+)\}/' , '(?P<\1>[a-z-]+)' , $ route ) ; // Convert variables with custom regular expressions e.g. {id:\d+} $ route = preg_replace ( '/\{([a-z]+):([^\}]+)\}/' , '(?P<\1>\2)' , $ route ) ; // Add start and end delimiters, and case insensitive flag $ route = '/^' . $ route . '$/i' ; //If array if ( is_array ( $ params ) ) { $ methodArray = [ 'method' => $ methods ] ; $ params = array_merge ( $ params , $ methodArray ) ; $ this -> routes [ $ route ] = $ params ; } elseif ( is_string ( $ params ) ) { //If string $ param = [ ] ; $ parts = explode ( '@' , $ params ) ; $ param [ 'controller' ] = $ parts [ 0 ] ; $ param [ 'action' ] = $ parts [ 1 ] ; $ param [ 'method' ] = $ methods ; if ( isset ( $ parts [ 2 ] ) ) { $ param [ 'namespace' ] = $ parts [ 2 ] ; } //If middleware is set then used ( ! empty ( $ middleware ) ) ? $ param [ 'middleware' ] = $ this -> addMiddleware ( $ middleware ) : $ param ; $ this -> routes [ $ route ] = $ param ; } elseif ( is_callable ( $ params ) ) { ( ! empty ( $ middleware ) ) ? $ this -> routes [ $ route ] = [ 'callable' => $ params , 'method' => $ methods , 'middleware' => $ this -> addMiddleware ( $ middleware ) ] : $ this -> routes [ $ route ] = [ 'callable' => $ params , 'method' => $ methods ] ; } else { throw new \ Exception ( 'Wrong agruments given' , 500 ) ; } }
Add a route to the routing table.

@param string       $route      The route URL
@param array|string $params     Parameters (controller, action, etc.) or $params Home@index
@param string       $methods    request method like GET or GET|POST
@param string       $middleware Middleare name

@since 1.0.0

@return void
Add a route to the routing table .