Parse Middlewares to pipelines

@param array $middlewares
@return array
420502
protected function parseMiddlewareToPipelines(array $middlewares) : array
    {
        $pipes = [];
        // check all types and store value into pipes array
        foreach ($middlewares as $middleware) {
            if (is_object($middleware)) {
                $pipes[] = $middleware;
            } elseif (string_has($middleware, ':')) {
                $pipes[] = $middleware;
            } else {
                $pipes[] = $this->container->make($middleware);
            }
        }

        return $pipes;
    }
617438
protected function sendThroughPipeline(array $middleware, \Closure $then)
    {
        if (count($middleware) > 0) {
            return (new Pipeline($this))
                ->send($this)
                ->through($middleware)
                ->then($then);
        }

        return $then();
    }
1187569
public function middleware($middleware, array $options = [])
    {
        if (!isset($options['only']) or ! app('antares.installed')) {
            return $this->runMiddleware($middleware, $options);
        }


        $route = Route::getCurrentRoute();
        if (!$route) {
            return;
        }

        $routeAction = $route->getAction();
        list($controller, $action) = explode('@', $routeAction['controller']);
        if (is_null($controller) or is_null($action)) {
            return $this->runMiddleware($middleware, $options);
        }

        $middlewareMatch = (is_array($options['only'])) ? in_array($action, $options['only']) : $action == $options['only'];
        if ($middlewareMatch) {
            $replacement = 'antares.can:';
            if (starts_with($middleware, $replacement)) {
                @list($component, $resource) = explode('::', preg_replace("/{$replacement}/", '', $middleware));
                if (is_null($resource)) {
                    $resource  = $component;
                    $component = 'antares/foundation';
                }
                app('antares.resource.repository')->add([
                    'component' => str_replace('/', '::', $component),
                    'resource'  => $resource,
                    'action'    => $action
                ]);
            }
        }
        return $this->runMiddleware($middleware, $options);
    }
191594
private function createWrapperMiddlewares(){
        $middlewares    = [];

        $middlewares[]  = $this->container->get("core.middleware.error");

        if($this->isDebug()){
            $middlewares[]  = $this->container->get("core.middleware.debug");
        }

        $middlewares[]  = $this->container->get("core.middleware.wrapper");

        return $middlewares;
    }
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;
	}
884092
private function applyMiddleware(array $configuration): array
    {
        foreach ($this->middlewares as $middleware) {
            $configuration = $middleware($configuration);
        }

        return $configuration;
    }
410256
public static function factory(array $middlewares = array())
    {
        $runner = null;
        foreach ($middlewares as $middleware) {
            $runner = $runner ? $runner->add($middleware) : new static($middleware);
        }
        return $runner;
    }
419286
public static function addStaticMiddlewares(...$middlewares): array
    {
        $stack = static::getStaticMiddlewareStack(true);
        foreach ($middlewares as $middleware) {
            $stack->append($middleware);
        }
        return $middlewares;
    }
242605
public function resolveMiddlewareClassName( $name )
	{
		$map = $this->middleware;

		// If the middleware is the name of a middleware group, we will return the array
		// of middlewares that belong to the group. This allows developers to group a
		// set of middleware under single keys that can be conveniently referenced.
		if ( isset( $this->middlewareGroups[$name] ) )
		{
			return $this->parseMiddlewareGroup( $name );
			// When the middleware is simply a Closure, we will return this Closure instance
			// directly so that Closures can be registered as middleware inline, which is
			// convenient on occasions when the developers are experimenting with them.
		}
		elseif ( isset( $map[$name] ) && $map[$name] instanceof Closure )
		{
			return $map[$name];
			// Finally, when the middleware is simply a string mapped to a class name the
			// middleware name will get parsed into the full class name and parameters
			// which may be run using the Pipeline which accepts this string format.
		}
		else
		{
			list( $name, $parameters ) = array_pad( explode( ':', $name, 2 ), 2, null );

			return ( isset( $map[$name] ) ? $map[$name] : $name ) . ( $parameters !== null ? ':' . $parameters : '' );
		}
	}
462715
public function compile($middleware)
    {
        if ($middleware instanceof MiddlewareFactory) {
            $subMiddlewares = $middleware->getSubMiddlewares();

            // Recursive compilation in sub-middlewares
            $subMiddlewares = array_map([$this, 'compile'], $subMiddlewares);

            $middleware = $middleware->create($this->container, $subMiddlewares);
        }

        return $middleware;
    }
498598
public function addMiddlewares(...$middlewares): array
    {
        $stack = $this->getMiddlewareStack(true);
        foreach ($middlewares as $middleware) {
            $stack->append($middleware);
        }
        return $middlewares;
    }
390228
public function middleware($middleware)
    {
        $middleware = (array) $middleware;

        if (! is_array($this->cb)) {
            $this->cb = [
                'controller' => $this->cb,
                'middleware' => $middleware
            ];

            return $this;
        }


        if (!isset($this->cb['middleware'])) {
            $this->cb['middleware'] = $middleware;
        } else {
            $this->cb['middleware'] = array_merge($middleware, (array) $this->cb['middleware']);
        }

        return $this;
    }
1170997
public function insertMiddlewares(array $middlewares, $offset = null)
    {
        null === $offset && $offset = $this->offset;
        $chunkArray = array_chunk($this->middlewares, $offset);
        $after = [];
        $before = $chunkArray[0];
        if (isset($chunkArray[1])) {
            $after = $chunkArray[1];
        }
        $middlewares = array_merge((array)$before, $middlewares, (array)$after);
        $this->middlewares = $middlewares;
        return $this;
    }
1206879
public function prepend(MiddlewareInterface $middleware): MiddlewarePipe
    {
        $stack = new MiddlewarePipe();

        /** @noinspection PhpParamsInspection */
        return $stack
            ->prepend($this)
            ->prepend($middleware);
    }
278724
protected function parseMiddleware($middleware)
    {
        list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, array());

        if (is_string($parameters)) {
            $parameters = explode(',', $parameters);
        }

        return array($name, $parameters);
    }
758058
public function pipes(array $middlewares): App
    {
        foreach ($middlewares as $key => $middleware) {
            if (is_numeric($key)) {
                $this->pipe($middleware);
                continue;
            }
            $this->pipe($middleware, $key);
        }
        return $this;
    }
316827
public function resolve($middlewares)
    {
        $last = function ($request, $response) {
            // no op
        };
        while ($middleware = array_pop($middlewares)) {
            if (is_object($middleware)) {
                if (method_exists($middleware, '__invoke')) {
                    $middleware = [$middleware, '__invoke'];
                }
            }

            if (!is_callable($middleware)) {
                throw new \InvalidArgumentException('Middle needs to be callable');
            }

            $last = function () use ($middleware, $last) {
                $args = func_get_args();
                $args[] = $last;
                return call_user_func_array($middleware, $args);
            };
        }
        return $last;
    }