@param callable|array $handler

@return static
162825
public function start($handler)
    {
        echo PHP_EOL, str_repeat('+', 80), PHP_EOL;

        $settings = isset($this->configure->servers['http']) ? $this->configure->servers['http'] : [];

        if (!empty($settings['enable_static_handler'])) {
            $settings['document_root'] = $_SERVER['DOCUMENT_ROOT'];
            if ($this->configure->debug) {
                $this->log('warn', 'enable `enable_static_handler` setting of swoole will reduce performance!!!!');
                sleep(3);
            }
        }

        if (isset($settings['host'])) {
            $this->_host = $settings['host'];
        }

        if (isset($settings['port'])) {
            $this->_port = (int)$settings['port'];
        }

        $settings['enable_coroutine'] = MANAPHP_COROUTINE ? true : false;

        $this->_settings = $settings;

        $this->_swoole = new \swoole_http_server($this->_host, $this->_port);
        $this->_swoole->set($this->_settings);
        $this->_handler = $handler;

        $this->log('info',
            sprintf('starting listen on: %s:%d with setting: %s', $this->_host, $this->_port, json_encode($this->_settings, JSON_UNESCAPED_SLASHES)));

        $this->_swoole->on('request', [$this, 'onRequest']);

        $this->_swoole->start();
        echo sprintf('[%s][info]: shutdown', date('c')), PHP_EOL;

        return $this;
    }
787338
public function group(string $prefix, callable $handler) : RouterInterface {
        $this->setPrefix($prefix);
        $handler($this);
        $this->setPrefix('');
        return $this;
    }
30901
public function setRequestHandler(RequestHandler $handler)
    {
        $handlerName = $handler->getName();
        $this->handlers[$handlerName] = $handler;
        return $this;
    }
959616
protected function createHandler(
        callable $handler,
        array $handlerParams,
        PsrContainerInterface $container
    ): Closure {
        return function (ServerRequestInterface $request = null) use (
            $handler,
            $handlerParams,
            $container
        ): ResponseInterface {
            try {
                return $this->callHandler($handler, $handlerParams, $container, $request);
            } catch (Throwable $throwable) {
                return $this->handleThrowable($throwable, $container);
            }
        };
    }
1232684
public function register(string $signal, callable $handler): self
    {
        $this->handlers[$signal][] = $handler;

        return $this;
    }
391632
public function setClassForString(Callable $handler): ColumnInterface
    {
        $this->key = self::ACTION_STRING_TR;
        $this->setHandler($handler);

        return $this;
    }
571502
public function register($name, $handler)
    {
        if (is_callable($handler)) {
            $params = array_merge(array($this), $this->params);
            $this->container[$name] = call_user_func_array($handler, $params);

        } else {
            $this->container[$name] = $handler;
        }

        return $this;
    }
222531
public function pipe($name, $handler = null)
    {
        if (is_callable($name)) {
            $handler = $name;
            $name    = null;
        }

        return $handler($this->getRepository($name), $this);
    }
1082599
public function bind($event, callable $handler)
    {
        if (in_array($event, [self::EVENT_INIT, self::EVENT_FORK, self::EVENT_START])) {
            throw new InvalidArgumentException('You can not bind a callback for this event');
        }

        parent::bind($event, $handler);
    }
1360163
public function setHandler($handler)
    {
        $handler = new $handler($this->config);

        if (!$handler instanceof HandlerInterface) {
            throw new \RuntimeException('Handler not initialized. Please use Handler class instanceof HandlerInterface.');
        }

        $this->handler = $handler;

        return $this;
    }
1165095
public function handler($handler)
    {
        if ($this->formDtoMappingCallback) {
            if (!($handler instanceof IParameterizedActionHandler)) {
                list($handler, $parameterDtoType) = $this->wrapArrayParameterAsDto($handler);
                $handler = new CustomParameterizedActionHandler($handler, $this->returnDtoType, $parameterDtoType);
            }

            /** @var IStagedFormDtoMapping $mapping */
            $mapping = call_user_func($this->formDtoMappingCallback, $handler->getParameterTypeClass());

            call_user_func($this->callback, new ParameterizedAction(
                $this->name,
                $this->authSystem,
                $this->requiredPermissions,
                $mapping,
                $handler,
                $this->metadata
            ));
        } else {

            if (!($handler instanceof IUnparameterizedActionHandler)) {
                $handler = new CustomUnparameterizedActionHandler($handler, $this->returnDtoType);
            }

            call_user_func($this->callback, new UnparameterizedAction(
                $this->name,
                $this->authSystem,
                $this->requiredPermissions,
                $handler,
                $this->metadata
            ));
        }
    }
791131
public function addFatalErrorHandler($handler) {
        if ( ! $handler instanceof INativeErrorHandler && ! is_callable($handler)) {
            throw new InvalidHandlerType(
                s('Fatal error handler must be a callable or an instance of %s.',
                    INativeErrorHandler::class)
            );
        }

        if (is_callable($handler)) {
            $handler = $this->createNativeErrorHandler($handler);
        }

        $this->fatalErrorHandlers[] = $handler;
    }
654341
public function executeHandler($request, $handler)
    {
        // execute actions as middleware
        if (!is_array($handler) || is_callable($handler)) {
            $handler = [$handler, \Bit55\Midcore\Middleware\NotFoundHandler::class];
        }
        $dispatcher = new Dispatcher($handler, $this->container);

        return $dispatcher->dispatch($request);
    }
369172
public function instantiate(string $handler) : EventHandler
    {
        $handler = ltrim($handler, '\\');
        if (false === $this->container->has($handler)) {
            throw new InvalidArgumentException(
                sprintf('Handler %s could not be found. Did you register it?', $handler)
            );
        }

        return $this->container->get($handler);
    }
764689
public function map($handler)
    {
        $result = array();

        foreach ($this as $id => $document) {
            $result[$id] = $handler($document);
        }

        return $result;
    }
1358975
public function withHandler(RequestHandlerInterface $handler): self
    {
        $pipeline = clone $this;
        $pipeline->handler = $handler;
        $pipeline->position = 0;

        return $pipeline;
    }
1129831
public function setHandler($handler)
    {
        if (Assert::array($handler)) {
            $this->handler = function (Event $event) use ($handler) {
                return call_user_func_array($handler, [$event]);
            };
        } elseif (Assert::instanceOf($handler, '\\Closure')) {
            $this->handler = $handler;
        } else {
            throw new InvalidArgumentException('`Listener::$handler` must be `array` or `Closure`');
        }
    }