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

Breadcrumb

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

class ExtensionHookManager

@phan-file-suppress PhanUndeclaredClassAttribute

Hierarchy

  • class \OpenTelemetry\API\Instrumentation\AutoInstrumentation\ExtensionHookManager implements \OpenTelemetry\API\Instrumentation\AutoInstrumentation\HookManagerInterface

Expanded class hierarchy of ExtensionHookManager

File

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

Namespace

OpenTelemetry\API\Instrumentation\AutoInstrumentation
View source
final class ExtensionHookManager implements HookManagerInterface {
    
    /**
     * @phan-suppress PhanUndeclaredFunction
     */
    public function hook(?string $class, string $function, ?Closure $preHook = null, ?Closure $postHook = null) : void {
        assert(extension_loaded('opentelemetry'));
        
        /** @noinspection PhpFullyQualifiedNameUsageInspection */
        \OpenTelemetry\Instrumentation\hook($class, $function, $this->bindHookScope($preHook), $this->bindHookScope($postHook));
    }
    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);
        };
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExtensionHookManager::bindHookScope private function
ExtensionHookManager::hook public function @phan-suppress PhanUndeclaredFunction Overrides HookManagerInterface::hook

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal