Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExtensionHookManager.php

function ExtensionHookManager::bindHookScope

1 call to ExtensionHookManager::bindHookScope()
ExtensionHookManager::hook in vendor/open-telemetry/api/Instrumentation/AutoInstrumentation/ExtensionHookManager.php
@phan-suppress PhanUndeclaredFunction

File

vendor/open-telemetry/api/Instrumentation/AutoInstrumentation/ExtensionHookManager.php, line 29

Class

ExtensionHookManager
@phan-file-suppress PhanUndeclaredClassAttribute

Namespace

OpenTelemetry\API\Instrumentation\AutoInstrumentation

Code

private function bindHookScope(?Closure $closure) : ?Closure {
    if (!$closure) {
        return null;
    }
    $reflection = new ReflectionFunction($closure);
    // TODO Add an option flag to ext-opentelemetry `hook` that configures whether return values should be used?
    if (!$reflection->getReturnType() || (string) $reflection->getReturnType() === 'void') {
        return static function (mixed ...$args) use ($closure) : void {
            if (HookManager::disabled()) {
                return;
            }
            $closure(...$args);
        };
    }
    return static function (mixed ...$args) use ($closure) : mixed {
        if (HookManager::disabled()) {
            return $args[2];
        }
        return $closure(...$args);
    };
}
RSS feed
Powered by Drupal