registers a middleware programmatically and not through a route
171904
public function registerMiddleware($middlewareInstance)
    {
        if (isset(class_uses($middlewareInstance)['Nf\Middleware\Pre'])) {
            $key = self::MIDDLEWARE_PRE;
        } else {
            $key = self::MIDDLEWARE_POST;
        }
        // adds the middleware
        $this->registeredMiddlewares[$key][] = $middlewareInstance;
    }
555690
protected function registerMiddleware()
    {
        $this->app->singleton(Request::class, function ($app) {
            $middleware = new Middleware\Request(
                $app,
                $app[ExceptionHandler::class],
                $app[Router::class],
                $app[RequestValidator::class],
                $app['events']
            );

            $middleware->setMiddlewares($this->config('middleware', false));

            return $middleware;
        });

        $this->app->singleton(AuthMiddleware::class, function ($app) {
            return new Middleware\Auth($app[Router::class], $app[Auth::class]);
        });

        $this->app->singleton(RateLimit::class, function ($app) {
            return new Middleware\RateLimit($app[Router::class], $app[Handler::class]);
        });

        $this->app->singleton(PrepareController::class, function ($app) {
            return new Middleware\PrepareController($app[Router::class]);
        });
    }
1168272
static public function register(Application $app,
                                    callable $callback = null,
                                    $prefix='/docs')
    {
        $app->addRoute('GET', $prefix.'/swagger.json', function (Application $app)use($callback){
            $swagger = new Swagger();
            $swagger->appendControllers($app, $app->getControllers());
            if($callback){
                $callback($swagger);
            }
            return new Response($swagger->toJson());
        });
    }
110454
def register(self, *paths, methods=None, name=None):
        """"""
        if isinstance(methods, str):
            methods = [methods]

        def wrapper(handler):

            if isinstance(handler, (FunctionType, MethodType)):
                handler = RESTHandler.from_view(handler, *(methods or ['GET']))

            if handler.name in self.handlers:
                raise muffin.MuffinException('Handler is already registered: %s' % handler.name)

            self.handlers[tuple(paths or ["/{0}/{{{0}}}".format(handler.name)])] = handler

            handler.bind(self.app, *paths, methods=methods, name=name or handler.name)
            return handler

        # Support for @app.register(func)
        if len(paths) == 1 and callable(paths[0]):
            view = paths[0]
            paths = []
            return wrapper(view)

        return wrapper
878235
protected function registerRoutes()
    {
        $this->app['router']->group(config('langmanGUI.route_group_config'), function ($router) {
            $router->get('/langman', 'LangmanController@index');

            $router->post('/langman/scan', 'LangmanController@scan');

            $router->post('/langman/save', 'LangmanController@save');

            $router->post('/langman/add-language', 'LangmanController@addLanguage');
        });
    }
1172263
protected function registerApiRouteMiddleware()
    {
        foreach ($this->getApiRouteMiddleware() as $key => $middleware) {
            $this->router->aliasMiddleware($key, $middleware);
        }

        return $this;
    }
1255972
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'));
            }
        }
    }
1336510
public function registerMiddleware()
    {
        if (is_array($this->middleware()) && count($this->middleware()))
        {
            $middleware = new Middleware($this);
            return $middleware->add();
        }
        return true;
    }
937799
protected function registerRoutes()
    {
        $this->app['router']->group([
            'middleware' => config('bone.captcha.middleware', 'web'),
            'namespace'  => 'Igoshev\Captcha\Controllers',
            'as'         => 'bone.captcha.'
        ], function ($router) {
            $router->get(config('bone.captcha.routes.image'), 'CaptchaController@image')->name('image');
            $router->get(config('bone.captcha.routes.image_tag'), 'CaptchaController@imageTag')->name('image.tag');
        });
    }
35568
protected function registerRoute($method, $path, $callback, $middleware = null)
    {
        if ($this->debug) echo __METHOD__ . " : " . json_encode([$method, $path, $callback, $middleware]) . PHP_EOL;
        $path = preg_replace('/\//', '\/', $path);
        $matched = preg_match_all('/\{([^\/]+)\}/', $path, $matches);
        if ($this->debug) echo "Regex Route Variable Components Matched: " . json_encode($matches) . PHP_EOL;
        if ($matched) {
            $regex = preg_replace('/\{([^\/]+)\}/', '([^\/]+)', $path);
        } else {
            $regex = $path;
        }
        $regex = '/^\/' . $regex . '$/';
        $new_route = [
            self::ROUTE_PARAM_METHOD => $method,
            self::ROUTE_PARAM_PATH => $regex,
            self::ROUTE_PARAM_CALLBACK => $callback,
            self::ROUTE_PARAM_MIDDLEWARE => $middleware,
        ];
        if ($this->debug) echo "New Regex Route: " . json_encode($new_route) . PHP_EOL;
        array_unshift($this->routes, $new_route);
    }
201223
function middlewareRegister(type) {
  Spider.prototype[type] = function(fn) {

    // Guard
    if (typeof fn !== 'function')
      throw Error('sandcrawler.spider.' + type + ': given argument is not a function');

    this.middlewares[type].push(fn.bind(this));
    return this;
  };
}
1125369
public function registerAuthRoutes()
    {
        Route::group(['prefix' => config('lia.route.prefix'), 'namespace' => 'Lia\Controllers', 'middleware' => 'api'], function($router){
            /* @var \Illuminate\Routing\Router $router */

            $router->get('auth/jwt', 'AuthController@jwt');
        });

        $attributes = [
            'prefix'     => config('lia.route.prefix'),
            'namespace'  => 'Lia\Controllers',
            'middleware' => config('lia.route.middleware'),
        ];

        Route::group($attributes, function ($router) {
            /* @var \Illuminate\Routing\Router $router */
            $router->group([], function ($router) {

                /* @var \Illuminate\Routing\Router $router */
                $router->resource('auth/users', 'UserController');
                $router->resource('auth/roles', 'RoleController');
                $router->resource('auth/permissions', 'PermissionController');
                $router->resource('auth/menu', 'MenuController', ['except' => ['create']]);
                $router->resource('auth/logs', 'LogController', ['only' => ['index', 'destroy']]);
            });

            $router->get('auth/login', 'AuthController@getLogin');
            $router->post('auth/login', 'AuthController@postLogin');
            $router->get('auth/logout', 'AuthController@getLogout');
            $router->get('auth/setting', 'AuthController@getSetting');
            $router->put('auth/setting', 'AuthController@putSetting');
        });
    }
381653
async function register(server, options) {
    const validation = validateOptions(options);

    if (validation.error) {
        throw validation.error;
    }

    const {
        components,
        handlebars,
        helpersPath,
        path,
        uriContext,
        routes,
        rootDir
    } = validation.value;


    server.log(['info', 'windshield'], "application directory identified as: " + rootDir);

    server.views({
        engines: {html: handlebars},
        relativeTo: rootDir,
        path,
        helpersPath
    });

    const componentMap = ComponentMap(components);

    const hapiHandler = handlerComposer(componentMap);
    const hapiRoutes = processRoutes(hapiHandler, uriContext, routes);
    server.route(hapiRoutes);
    templateInit(handlebars);

    return componentMap.init(handlebars);
}
554281
protected static function middleware()
    {
        foreach (self::fetch('http/middleware') as $file) {
            Bus::need($file);
        }

        Middleware::ini();
    }
221079
public function applyMiddleware($path, array $middleware)
    {
        foreach ($middleware as $name) {
            if (!$this->hasMiddleware($name) && !$this->hasMiddlewareGroup($name)) {
                $message = "Cannot apply '$name' middleware or middleware group to path '$path'. It has not been registered.";
                throw new RuntimeException($message);
            }
        }
        // Matches route element pattern in Cake\Routing\Route
        $path = '#^' . preg_quote($path, '#') . '#';
        $path = preg_replace('/\\\\:([a-z0-9-_]+(?<![-_]))/i', '[^/]+', $path);

        if (!isset($this->_middlewarePaths[$path])) {
            $this->_middlewarePaths[$path] = [];
        }
        $this->_middlewarePaths[$path] = array_merge($this->_middlewarePaths[$path], $middleware);

        return $this;
    }
845700
public function register(KernelInterface $kernel): void
    {
        $kernel->closure(RoutingMiddleware::class, function () use ($kernel) {
            return new RoutingMiddleware($kernel[RouterInterface::class], $kernel[ResponseFactoryInterface::class], $kernel[StreamFactoryInterface::class]);
        });

        $kernel->closure(DispatcherMiddleware::class, function () use ($kernel) {
            return new DispatcherMiddleware(new Pipeline($kernel));
        });

        $kernel->closure(ContentTypeByDefaultMiddleware::class, function () {
            return new ContentTypeByDefaultMiddleware();
        });
        /*
        $kernel->closure(OriginalRequestMiddleware::class, function ($c) {
            return new OriginalRequestMiddleware();
        });*/

        $kernel->closure(CharsetByDefaultMiddleware::class, function () {
            return new CharsetByDefaultMiddleware();
        });
        /*
        $kernel->closure(BodyParserMiddleware::class, function ($c) {
            return new BodyParserMiddleware();
        });*/

        /*
                $kernel[EmitterMiddleware::class] = function ($c) {
                    return new EmitterMiddleware();
                };
        */

        $kernel->closure(CheckMaintenanceMiddleware::class, function () {
            return new CheckMaintenanceMiddleware();
        });

        $kernel->closure(MethodOverrideMiddleware::class, function () {
            return new MethodOverrideMiddleware();
        });

        $kernel->closure(ContentLengthMiddleware::class, function () {
            return new ContentLengthMiddleware();
        });

        /*
           $kernel['controllerResolver'] = function ($container) {
               return new ControllerResolver($container);
           };
        */

        //$this->factory = new MiddlewareFactory($this->container);

        //$this->loadConfig($config_path_or_file_or_array, $config_cache_file);

        // TODO : déplacer ces initialisations dans le constructeur d'une classe CONTAINER externalisée

        // TODO : ajouter l'initialisation d'un logger ?????

        // TODO : vérifier l'utilité de mettre cela dans un container, normalement on va toujours passer par le router, donc le mettre dans un container n'est pas vraiment nécessaire, surtout que dans les controller on ne va pas réutiliser le router, car la méthode redirect ou getPathFor se trouve directement dans $app et pas dans la classe Router.
        // register the router in the pimple container

        /*
            $this['session'] = function ($c) {
                // TODO : déplacer la classe session dans le répertoire "components"
                return new Session();
            };
        */

        /*
            $this['router'] = function ($c) {
                return new Router($c->get('basePath'), $this->container);
            };
        */

        // Create request class closure.
        /*
            $this['request'] = function ($c) {
                return Request::fromGlobals();
            };
        */

        // -----------------------------------------------------------------------------
        // Service providers
        // -----------------------------------------------------------------------------
        // Twig
        // TODO : s'inspirer de ce bout de code pour passer des variables global directement à phpRenderer
        /*
        $view = new \Slim\Views\Twig(
            $app->settings['view']['template_path'],
            $app->settings['view']['twig']
        );
        $view->addExtension(new Twig_Extension_Debug());
        $view->addExtension(new \Slim\Views\TwigExtension($app->router, $app->request->getUri()));
        */
        /* @var \Twig_Environment $env */
        /*
        $env = $view->getEnvironment();
        foreach ($app->settings['view']['globals'] as $global => $value) {
            $env->addGlobal($global, $value);
        }
        $container->register($view);*/

        // LOAD Referral Spammer List
        //$spammerList = config('app.referral_spam_list_location', base_path('vendor/matomo/referrer-spam-blacklist/spammers.txt'));
    }
651745
public function register_routes() {

		register_rest_route(
			$this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, [
				'args' => [
					'parent' => [
						'required' => true,
						'description' => __( 'The ID for the parent of the object.' ),
						'type' => 'integer',
					],
				],
				[
					'methods' => \WP_REST_Server::READABLE,
					'callback' => [ $this, 'get_item' ],
					'permission_callback' => [ $this, 'get_item_permissions_check' ],
					'args' => [
						'context' => $this->get_context_param(
							[
								'default' => 'view',
							]
						),
					],
				],
				'schema' => [ $this, 'get_public_item_schema' ],
			]
		);
	}