, * ?Context=, * ?CodeLocation= * ) : ?array> * > */ private static $handlers = []; public function __construct() { self::$handlers = []; } /** * @param class-string $class * @psalm-suppress PossiblyUnusedParam * @return void */ public function registerClass(string $class) { if (version_compare(PHP_VERSION, '7.1.0') >= 0) { /** * @psalm-suppress UndefinedMethod * @var \Closure */ $callable = \Closure::fromCallable([$class, 'getFunctionParams']); } else { $callable = (new \ReflectionClass($class))->getMethod('getFunctionParams')->getClosure(new $class); if (!$callable) { throw new \UnexpectedValueException('Callable must not be null'); } } foreach ($class::getFunctionIds() as $function_id) { /** @psalm-suppress MixedTypeCoercion */ $this->registerClosure($function_id, $callable); } } /** * @param \Closure( * StatementsSource, * string, * array, * ?Context=, * ?CodeLocation= * ) : ?array $c * * @return void */ public function registerClosure(string $fq_classlike_name, \Closure $c) { self::$handlers[strtolower($fq_classlike_name)][] = $c; } public function has(string $fq_classlike_name) : bool { return isset(self::$handlers[strtolower($fq_classlike_name)]); } /** * @param array $call_args * @return ?array */ public function getFunctionParams( StatementsSource $statements_source, string $function_id, array $call_args, Context $context = null, CodeLocation $code_location = null ) { foreach (self::$handlers[strtolower($function_id)] as $class_handler) { $result = $class_handler( $statements_source, $function_id, $call_args, $context, $code_location ); if ($result) { return $result; } } return null; } }