Add middleware's to pipe

@param Middleware $middleware
@param string $alias
@return App
@throws SimplesAlreadyRegisteredError
763280
public function pipe(Middleware $middleware, string $alias = ''): App
    {
        $alias = $alias ? $alias : $middleware->alias();
        if (isset($this->pipe[$alias])) {
            throw new SimplesAlreadyRegisteredError("The middleware `{$alias}` is already registered");
        }
        $this->pipe[$alias] = $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;
    }
1193825
public function pipe($middlewares): self
    {
        //Add middleware to the end of the stack => Append
        //array_push($this->middlewares, $this->decorate($middleware));

        if (! is_array($middlewares)) {
            $middlewares = [$middlewares];
        }

        foreach ($middlewares as $middleware) {
            $this->middlewares[] = $this->decorate($middleware);
        }

        return $this;
    }
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);
    }
140508
public function addMiddleware(Middleware $middleware)
    {
        $group = $middleware->getGroup();
        if (! isset($this->middleware[$group])) {
            $this->middleware[$group] = array(
                'before' => array(),
                'after' => array()
            );
        }

        $this->middleware[$group][$middleware->getPosition()][] = &$middleware;
    }
1326345
public function middleware($middleware, $name = null)
	{
        if($name)
            $this->properties['middleware'][$name] = $middleware;
        else
            $this->properties['middleware'][] = $middleware;

		return $this;
	}
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;
    }
468076
public function pipe($middleware, array $params = [])
    {
        if (is_callable($middleware)) {
            $this->middlewares[] = $middleware;
        } else {
            $this->middlewares[] = ['class' => $middleware, 'params' => $params];
        }

        return $this;
    }
1355740
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        if (is_array($middleware) && isset($middleware['priority'])) {
            $priority = $middleware['priority'];
        }

        $this->getMiddlewares()->insert($middleware, $priority);

        return $this;
    }
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;
    }
497776
protected function registerMiddleware($router)
    {
        if (method_exists($router, 'aliasMiddleware')) {
            $router->aliasMiddleware('site', CurrentSite::class);
        } else {
            $router->middleware('site', CurrentSite::class);
        }
    }
1225751
public function append(MiddlewareInterface $middleware){
        if($this->isAlreadyRegistered($middleware)){
            throw new Exception\MiddlewareAlreadyRegisteredException(
                static::createMsgAlreadyRegisterd($middleware)
            );
        }

        $this->registerd[$middleware]   = true;

        $this->queue->push($middleware);

        return $this;
    }
1172263
protected function registerApiRouteMiddleware()
    {
        foreach ($this->getApiRouteMiddleware() as $key => $middleware) {
            $this->router->aliasMiddleware($key, $middleware);
        }

        return $this;
    }
667702
public function prepend(MiddlewareInterface $middleware){
        if($this->isAlreadyRegistered($middleware)){
            throw new Exception\MiddlewareAlreadyRegisteredException(
                static::createMsgAlreadyRegisterd($middleware)
            );
        }

        $this->registerd[$middleware]   = true;

        $this->queue->unshift($middleware);

        return $this;
    }
238279
private function pushMiddlewaresInDefinition($alias_namespace, $middlewares_directory, &$default_definitions)
    {
        $middleware_files = get_files($middlewares_directory);
        if (!empty($middleware_files))
        {
            $middlewares = array_map(function($middleware) use($middlewares_directory) {
                $new_middleware = str_replace("{$middlewares_directory}/", "", $middleware);
                return basename(str_replace("/", "\\", $new_middleware), ".php");
            }, $middleware_files);

            $errors = [];

            foreach ($middlewares as $middleware) {
                if ($alias_namespace === "\\")
                {
                    $middleware_definition = $middleware;
                    $middleware_definition_value = get_app_namespace() . "Middlewares\\{$middleware}";
                }
                else
                {
                    $module_name = str_replace("App\\", "", $alias_namespace);

                    $middleware_sub_namespace = str_replace(app_path() . "/{$module_name}/Middlewares", "", $middlewares_directory);
                    $middleware_sub_namespace = str_replace("/", "\\", $middleware_sub_namespace);

                    $middleware_definition = "{$alias_namespace}{$middleware}";
                    $middleware_definition_value = "{$alias_namespace}Middlewares\\{$middleware}";
                }

                if (!array_key_exists("{$middleware_definition}", $default_definitions))
                {
                    $default_definitions["{$middleware_definition}"] = function(ContainerInterface $c) use ($middleware_definition_value)
                    {
                        return new $middleware_definition_value($c);
                    };
                }
                else
                {
                    $errors[] = "{$middleware} is already exist inside of definitions.";
                }
            }

            if (!empty($errors))
            {
                exit("Error: Please fix the ff. before run the application: <li>" . implode("</li><li>", $errors));
            }
        }
        else
        {
            exit("Error: No middleware found in {$middlewares_directory} path.");
        }
    }
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;
    }
1315684
public function addMiddleware($middleware, array $properties = array())
    {
        if($this->route)
        {
            $this->route->addMiddleware($middleware, $properties);
        }
        else
        {
            $this->middlewares[] = array($middleware, $properties);
        }

        return $this;
    }