getHandler

@param  $handler
@throws InvalidArgumentException

@return callable
779648
protected function getHandler($handler)
    {
        if ($handler instanceof HandlerInterface) {
            return [$handler, 'handleEvent'];
        }

        if (is_callable($handler)) {
            return $handler;
        }

        throw new InvalidArgumentException(
            sprintf('Invalid handler "%s".', is_string($handler) ? $handler : gettype($handler))
        );
    }
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);
    }
1082955
public function setRequestHandler($handler)
    {
        $this->requestHandler = $handler;

        $this->requestHandler->setUri($this->url)
            ->setMethod($this->method);

        $this->requestHandler->getUri()->setPort($this->port);

        return $this;
    }
948798
public function get(string $name) : EventHandlerInterface
    {
        if (!isset($this->eventHandlers[$name])) {
            throw new \InvalidArgumentException(sprintf('DataGrid event handler %s not found', $name));
        }

        return $this->eventHandlers[$name];
    }
913914
protected function getHandler()
    {
        $stack = HandlerStack::create();

        foreach ($this->middlewares as $middleware) {
            $stack->push($middleware);
        }

        if (isset(static::$defaults['handler']) && is_callable(static::$defaults['handler'])) {
            $stack->push(static::$defaults['handler'], self::USER_DEFINED_HANDLER);
        }

        return $stack;
    }
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);
            }
        };
    }
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`');
        }
    }
534828
public function handler($handler = null)
    {
        if ($handler !== null) {
            $this->handler = $this->getRealHandler($handler);
        }

        return $this->handler;
    }
1080854
public function get($path, callable $handler): RouterInterface
    {
        $ruler = $this->createRuler('GET', $path);
        return $this->addRuler($ruler, $handler);
    }
1196620
public function get($name)
    {
        if (isset($this->_handlers[$name])) {
           return $this->_handlers[$name];
        }
        $checker = $this->_classes['checker'];
        if ($checker::has($name)) {
           return $checker::get($name);
        }
        throw new InvalidArgumentException("Unexisting `{$name}` as validation handler.");
    }
1142598
public function get(string $path, $handler)
  {
    return $this->request($path, Request::HTTP_GET | Request::HTTP_HEAD, $handler);
  }
621710
public static function callback($handler)
    {
        if ($handler instanceof Closure) {
            return $handler;
        }
        if (is_object($handler[0])) {
            return $handler;
        }

        // If the first argument is a class name string,
        // then create the controller object.
        if (is_string($handler[0])) {

            // If users define the constructor arguments in options array.
            $constructArgs = [];
            $rc = new ReflectionClass($handler[0]);
            if (isset($options['constructor_args'])) {
                $con = $handler[0] = $rc->newInstanceArgs($constructArgs);
            } else {
                $con = $handler[0] = $rc->newInstance();
            }

            return $handler;
        }

        throw new LogicException('Unsupported handler type');
    }
219165
protected function callHandler(callable $handler, $payload)
    {
        try {
            return $handler($payload);
        } catch (\Exception $e) {
            if (property_exists($this, 'app') && $this->app instanceof ServiceContainer) {
                $this->app['logger']->error($e->getCode().': '.$e->getMessage(), [
                    'code' => $e->getCode(),
                    'message' => $e->getMessage(),
                    'file' => $e->getFile(),
                    'line' => $e->getLine(),
                ]);
            }
        }
    }
1120504
protected function executeHandler($handler, array $parameters)
	{
		if($handler instanceof Closure)
		{
			return $this->executeClosureHandler($handler, $parameters);
		}

		$handler = $this->resolveHandler($handler);

		return $this->executeClassHandler($handler, $parameters);
	}
1371099
private function findHandler($handler)
    {
        // if the handler is callable, return it immediately:
        if (is_callable($handler)) {
            return $handler;
        }

        if (!is_string($handler)) {
            throw new ResolverException(sprintf('Cannot resolver handler of type "%s".', gettype($handler)));
        }

        list ($handler, $method) = $this->resolveHandlerAndMethod($handler);

        // if the service parameter is registererd as service, return the
        // service object and its method as callable:
        if ($service = $this->getService($handler)) {
            return null === $method ? $service : [$service, $method];
        }

        if (!class_exists($handler)) {
            return [$handler, $method];
        }
        $err = null;

        set_error_handler(function ($errno, $msg) {
            throw $this->newResolverException($msg);
        });

        try {
            $resolvedHandler = [new $handler, $method];
        } catch (ResolverException $e) {
            $err = $e;
        } catch (\Throwable $t) {
            $err = $this->newResolverException($t->getMessage());
        }

        restore_error_handler();

        if (null !== $err) {
            throw $err;
        }

        return $resolvedHandler;
    }
378156
protected function getHandler()
    {
        if ($this->builder) {
            return $this->builder;
        }

        if ($this->query) {
            return $this->query;
        }

        throw new InvalidArgumentException('Missing query builder');
    }
925973
protected function reflection($handler)
    {
        if (! is_array($handler))
        {
            $instance = new \ReflectionFunction($handler);

            return array($handler, $instance);
        }

        list($class, $method) = (array) $handler;

        $instance = new \ReflectionMethod($class, $method);

        $handler = array($this->instance($class), $method);

        return array((array) $handler, $instance);
    }