public static function register($middleware)
    {
        $config = Container::get('config')->get('middleware');

        if (isset($config[$middleware])) {
            if (in_array($middleware, array_values(self::$middlewares))) {
                throw new ConfigException('middleware has already registered');
            }

            array_push(self::$middlewares, $middleware);
            $middlewares = $config[$middleware];

            if (!is_array($middlewares)) {
                throw new ConfigException('middleware config must be an array');
            }

            foreach ($middlewares as $className) {
                if (!class_exists($className)) {
                    throw new NotFoundException('middleware class ' . $className . ' is not found');
                }

                $class = new $className;
                if (!method_exists($class, 'handle')) {
                    throw new NotFoundException('middleware class should implement a handle() method');
                }

                $class->handle(Container::get('request'), Container::get('response'));
            }
        }
    }
public static function register($middleware)
    {
        $config = Container::get('config')->get('middleware');

        if (isset($config[$middleware])) {
            if (in_array($middleware, array_values(self::$middlewares))) {
                throw new ConfigException('middleware has already registered');
            }

            array_push(self::$middlewares, $middleware);
            $middlewares = $config[$middleware];

            if (!is_array($middlewares)) {
                throw new ConfigException('middleware config must be an array');
            }

            foreach ($middlewares as $className) {
                if (!class_exists($className)) {
                    throw new NotFoundException('middleware class ' . $className . ' is not found');
                }

                $class = new $className;
                if (!method_exists($class, 'handle')) {
                    throw new NotFoundException('middleware class should implement a handle() method');
                }

                $class->handle(Container::get('request'), Container::get('response'));
            }
        }
    }
public static function register ( $ middleware ) { $ config = Container :: get ( 'config' ) -> get ( 'middleware' ) ; if ( isset ( $ config [ $ middleware ] ) ) { if ( in_array ( $ middleware , array_values ( self :: $ middlewares ) ) ) { throw new ConfigException ( 'middleware has already registered' ) ; } array_push ( self :: $ middlewares , $ middleware ) ; $ middlewares = $ config [ $ middleware ] ; if ( ! is_array ( $ middlewares ) ) { throw new ConfigException ( 'middleware config must be an array' ) ; } foreach ( $ middlewares as $ className ) { if ( ! class_exists ( $ className ) ) { throw new NotFoundException ( 'middleware class ' . $ className . ' is not found' ) ; } $ class = new $ className ; if ( ! method_exists ( $ class , 'handle' ) ) { throw new NotFoundException ( 'middleware class should implement a handle() method' ) ; } $ class -> handle ( Container :: get ( 'request' ) , Container :: get ( 'response' ) ) ; } } }
Register a middleware

@param  string $middleware
@return void
Register a middleware