Sort array of fully qualified middleware class names by priority in ascending order.

@param  array<string> $middleware
@return array
431654
public function sortMiddleware( $middleware ) {
		$sorted = $middleware;

		usort( $sorted, function ( $a, $b ) use ( $middleware ) {
			$a_priority = $this->getMiddlewarePriorityForMiddleware( $a );
			$b_priority = $this->getMiddlewarePriorityForMiddleware( $b );
			$priority = $b_priority - $a_priority;

			if ( $priority !== 0 ) {
				return $priority;
			}

			// Keep relative order from original array.
			return array_search( $a, $middleware ) - array_search( $b, $middleware );
		} );

		return array_values( $sorted );
	}
1097497
public function middleware(...$middleware): self
    {
        foreach ($middleware as $handler) {
            $this->chains[] = $handler;
        }

        return $this;
    }
148767
public function pushMiddleware($middleware)
    {
        if (array_search($middleware, $this->middleware) === false) {
            array_push($this->middleware, $middleware);
        }

        return $this;
    }
88701
protected function resolveOnion(array $middleware): Onion
	{
		if(empty($middleware))
		{
			return $this->onion;
		}

		$onion = clone $this->onion;

		foreach($middleware as $layer)
		{
			$onion->addLayer($layer);
		}

		return $onion;
	}
698359
private static function collectMiddlewares(
        string $className,
        string $methodName,
        Middlewares $middlewaresAnnotation
    ) {
        $classMiddlewares = [];
        foreach ($middlewaresAnnotation->getMiddlewares() as $middleware) {
            if ($middleware instanceof Middleware) {
                $classMiddlewares[] = $middleware->getClass();
            }
        }
        $classMiddlewares = array_unique($classMiddlewares);

        if (! empty($methodName)) {
            $scanMiddlewares = self::$middlewares[$className]['middlewares']['actions'][$methodName] ?? [];
            self::$middlewares[$className]['middlewares']['actions'][$methodName] = array_unique(array_merge($classMiddlewares,$scanMiddlewares));
        } else {
            $scanMiddlewares = self::$middlewares[$className]['middlewares']['group'] ?? [];
            self::$middlewares[$className]['middlewares']['group'] = array_unique(array_merge($classMiddlewares, $scanMiddlewares));
        }
    }
709352
protected function gatherInvokerMiddleware($middleware)
    {
        $nameMiddleware = $this->config['name_middleware'] ?? [];
        $middlewareGroups = $this->config['middleware_groups'] ?? [];

        return Collection::make($middleware)->map(function ($middleware) use ($nameMiddleware, $middlewareGroups) {
            return (array) MiddlewareNameResolver::resolve($middleware, $nameMiddleware, $middlewareGroups);
        })->flatten()->all();
    }
173801
public function setMiddleware($middleware, array $properties = array())
	{
		// reset on each call
		$this->properties['middleware'] = array();

		if(!is_array($middleware))
		{
			$this->properties['middleware'][] = array($middleware, $properties);
		}
		else
		{
			foreach($middleware as $m)
				$this->properties['middleware'][] = array($m);
		}

		return $this;
	}
1299728
public function expandMiddlewareAtom( $middleware ) {
		if ( isset( $this->middleware[ $middleware ] ) ) {
			return $this->middleware[ $middleware ];
		}

		if ( class_exists( $middleware ) ) {
			return $middleware;
		}

		throw new ConfigurationException( 'Unknown middleware "' . $middleware . '" used.' );
	}
897373
public function middleware($middleware = null)
    {
        if (is_null($middleware)) {
            return (array) ($this->action['middleware'] ?? []);
        }

        if (is_string($middleware)) {
            $middleware = func_get_args();
        }

        $this->action['middleware'] = array_merge(
            (array) ($this->action['middleware'] ?? []), $middleware
        );

        return $this;
    }
1220892
protected function gatherMiddlewareClassNames($middleware)
    {
        $middleware = is_string($middleware) ? explode('|', $middleware) : (array) $middleware;

        return array_map(function ($name) {
            list($name, $parameters) = array_pad(explode(':', $name, 2), 2, null);

            return Arr::get($this->routeMiddleware, $name, $name).($parameters ? ':'.$parameters : '');
        }, $middleware);
    }
845982
public function setEndMiddleware($middleware)
    {
        $object = $this->marshalMiddleware($middleware);

        $this->endMiddleware = $object;

        return $this;
    }
770052
public static function middleware( $laravelMiddleware, $middleware = array() ) {
		$packageMiddleware = array();
		$path = base_path('config/packages.json');
		if( file_exists( $path ) ) {
			$data = json_decode( file_get_contents( $path ) );
			if( isset( $data->middleware ) ) {
				$packageMiddleware = (array)$data->middleware;
			}
		}
		return array_merge( $laravelMiddleware, $middleware, $packageMiddleware );
	}
1148749
public function middlewares(array $middlewares = []) {
        if (!$this->isGroupe) {
            end($this->virtualRoutes['*']);
            $lastKey = key($this->virtualRoutes['*']);
            $this->virtualRoutes['*'][$lastKey]['middlewares'] = $middlewares;
        } else {
            end($this->virtualRoutes);
            $lastKeyOfFirstRound = key($this->virtualRoutes);

            if (!$this->isGroupeMiddlewares) {
                end($this->virtualRoutes[$lastKeyOfFirstRound]);
                $lastKeyOfSecondRound = key($this->virtualRoutes[$lastKeyOfFirstRound]);
                $this->virtualRoutes[$lastKeyOfFirstRound][$lastKeyOfSecondRound]['middlewares'] = $middlewares;
            } else {
                $this->isGroupe = FALSE;

                foreach ($this->virtualRoutes[$lastKeyOfFirstRound] as &$route) {
                    $hasMiddleware = end($route);
                    if (!is_array($hasMiddleware)) {
                        $route['middlewares'] = $middlewares;
                    } else {
                        foreach ($middlewares as $middleware) {
                            $route['middlewares'][] = $middleware;
                        }
                    }
                }
            }
        }
    }
1326345
public function middleware($middleware, $name = null)
	{
        if($name)
            $this->properties['middleware'][$name] = $middleware;
        else
            $this->properties['middleware'][] = $middleware;

		return $this;
	}
884092
private function applyMiddleware(array $configuration): array
    {
        foreach ($this->middlewares as $middleware) {
            $configuration = $middleware($configuration);
        }

        return $configuration;
    }
652655
public function before($middlewares)
    {
        $count = count($middlewares);
        for ($i = 0; $i < $count; $i++) {
            $middlewares[$i]->getProxy()->before_handle();
        }
    }
936693
public function middleware($middleware, $param = null)
    {
        if (is_null($param) && is_array($middleware)) {
            $this->option['middleware'] = $middleware;
        } else {
            foreach ((array)$middleware as $item) {
                $this->option['middleware'][] = [$item, $param];
            }
        }

        return $this;
    }