src/Http/Kernel.php
/**
	 * Executes middleware.
	 *
	 * @param Route $route
	 * @param string $method `before` or `after`
	 * @throws HorizonException Middleware could not be found.
	 * @throws Exception Failed to bind contextual parameters.
	 */
Executes middleware.
@param Route $route
@param string $method `before` or `after`
@throws HorizonException Middleware could not be found.
@throws Exception Failed to bind contextual parameters.
Executes middleware . @param Route $route @param string $method ` before ` or ` after ` @throws HorizonException Middleware could not be found . @throws Exception Failed to bind contextual parameters .
private function executeMiddleware(Route $route, $method) {
		$middlewares = $route->middleware();
		$requestMethod = $this->request->getMethod();
		if ($this->response->isHalted()) {
			return;
		}
		foreach ($middlewares as $middleware) {
			$action = Str::parseCallback($middleware, $method . 'Execute');
			$className = head($action);
			if (class_exists($className)) {
				$callable = new BoundCallable($action, Application::container());
				$instance = $callable->instance();
								if ($instance instanceof Middleware) {
					if (in_array($requestMethod, $instance->methods)) {
						$callable->with($route);
						$callable->with($this->request);
						$callable->with($this->response);
						if (!is_null($this->request)) {
							foreach ($this->request->attributes->all() as $name => $value) {
								if (is_object($value)) {
									$callable->with($value);
								}
								$callable->where($name, $value);
							}
						}
						$callable->execute();
					}
				}
			}
			else {
				throw new HorizonException(0x0006, sprintf('Middleware (%s)', $className));
			}
			if ($this->response->isHalted()) {
				break;
			}
		}
	}
private function executeMiddleware ( Route $ route , $ method ) { $ middlewares = $ route -> middleware ( ) ; $ requestMethod = $ this -> request -> getMethod ( ) ; if ( $ this -> response -> isHalted ( ) ) { return ; } foreach ( $ middlewares as $ middleware ) { $ action = Str :: parseCallback ( $ middleware , $ method . 'Execute' ) ; $ className = head ( $ action ) ; if ( class_exists ( $ className ) ) { $ callable = new BoundCallable ( $ action , Application :: container ( ) ) ; $ instance = $ callable -> instance ( ) ; if ( $ instance instanceof Middleware ) { if ( in_array ( $ requestMethod , $ instance -> methods ) ) { $ callable -> with ( $ route ) ; $ callable -> with ( $ this -> request ) ; $ callable -> with ( $ this -> response ) ; if ( ! is_null ( $ this -> request ) ) { foreach ( $ this -> request -> attributes -> all ( ) as $ name => $ value ) { if ( is_object ( $ value ) ) { $ callable -> with ( $ value ) ; } $ callable -> where ( $ name , $ value ) ; } } $ callable -> execute ( ) ; } } } else { throw new HorizonException ( 0x0006 , sprintf ( 'Middleware (%s)' , $ className ) ) ; } if ( $ this -> response -> isHalted ( ) ) { break ; } } }
Executes middleware.
Executes middleware .
// Is this a valid middleware?
 // Add basic objects for dependency resolution // Add attribute objects // Run the middleware