src/Neutrino/Micro/Router.php
protected function pathToHandler($path){
        if ($path instanceof \Closure) {
            return $path;
        }

        if (is_array($path)) {
            return function (...$args) use ($path) {
                /** @var Micro $this */

                $controller = isset($path['controller']) ? $path['controller'] : null;
                $action = isset($path['action']) ? $path['action'] : null;

                $handler = $this->getDI()->get($controller);

                if (!method_exists($handler, $action)) {
                    throw new \RuntimeException('Method : "' . $action . '" doesn\'t exist on "' . $controller . '"');
                }

                if (isset($path['middlewares'])) {
                    foreach ($path['middlewares'] as $middleware => $params) {
                        if (is_string($params)) {
                            $middleware = $params;
                            $params = [];
                        }

                        /** @var \Neutrino\Foundation\Middleware\Controller $middleware */
                        $middlewares[] = $middleware = new $middleware($controller, ...$params);

                        if ($middleware instanceof BeforeInterface) {
                            if (!isset($event)) {
                                $event = new Event(Events\Micro::BEFORE_EXECUTE_ROUTE, $this);
                            }

                            $result = $middleware->before($event, $this, null);

                            if ($result === false) {
                                return $this->response;
                            }
                        }
                    }
                }

                $value = $handler->$action(...$args);

                if (isset($middlewares)) {
                    $event = null;
                    foreach ($middlewares as $middleware) {
                        if ($middleware instanceof AfterInterface) {
                            if (!isset($event)) {
                                $event = new Event(Events\Micro::AFTER_EXECUTE_ROUTE, $this);
                            }

                            $middleware->after($event, $this, null);
                        }
                    }
                }

                return $value;
            };
        }

        throw new \RuntimeException("invalid route paths");
    }
protected function pathToHandler($path){
        if ($path instanceof \Closure) {
            return $path;
        }

        if (is_array($path)) {
            return function (...$args) use ($path) {
                /** @var Micro $this */

                $controller = isset($path['controller']) ? $path['controller'] : null;
                $action = isset($path['action']) ? $path['action'] : null;

                $handler = $this->getDI()->get($controller);

                if (!method_exists($handler, $action)) {
                    throw new \RuntimeException('Method : "' . $action . '" doesn\'t exist on "' . $controller . '"');
                }

                if (isset($path['middlewares'])) {
                    foreach ($path['middlewares'] as $middleware => $params) {
                        if (is_string($params)) {
                            $middleware = $params;
                            $params = [];
                        }

                        /** @var \Neutrino\Foundation\Middleware\Controller $middleware */
                        $middlewares[] = $middleware = new $middleware($controller, ...$params);

                        if ($middleware instanceof BeforeInterface) {
                            if (!isset($event)) {
                                $event = new Event(Events\Micro::BEFORE_EXECUTE_ROUTE, $this);
                            }

                            $result = $middleware->before($event, $this, null);

                            if ($result === false) {
                                return $this->response;
                            }
                        }
                    }
                }

                $value = $handler->$action(...$args);

                if (isset($middlewares)) {
                    $event = null;
                    foreach ($middlewares as $middleware) {
                        if ($middleware instanceof AfterInterface) {
                            if (!isset($event)) {
                                $event = new Event(Events\Micro::AFTER_EXECUTE_ROUTE, $this);
                            }

                            $middleware->after($event, $this, null);
                        }
                    }
                }

                return $value;
            };
        }

        throw new \RuntimeException("invalid route paths");
    }
@param $path

@return \Closure