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

Breadcrumb

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

class Invoker

Hierarchy

  • class \SebastianBergmann\Invoker\Invoker

Expanded class hierarchy of Invoker

3 files declare their use of Invoker
ExcludeList.php in vendor/phpunit/phpunit/src/Util/ExcludeList.php
Merger.php in vendor/phpunit/phpunit/src/TextUI/Configuration/Merger.php
TestRunner.php in vendor/phpunit/phpunit/src/Framework/TestRunner.php

File

vendor/phpunit/php-invoker/src/Invoker.php, line 21

Namespace

SebastianBergmann\Invoker
View source
final class Invoker {
    private int $timeout;
    
    /**
     * @throws Throwable
     */
    public function invoke(callable $callable, array $arguments, int $timeout) : mixed {
        if (!$this->canInvokeWithTimeout()) {
            throw new ProcessControlExtensionNotLoadedException('The pcntl (process control) extension for PHP is required');
        }
        pcntl_signal(SIGALRM, function () : void {
            throw new TimeoutException(sprintf('Execution aborted after %d second%s', $this->timeout, $this->timeout === 1 ? '' : 's'));
        }, true);
        $this->timeout = $timeout;
        pcntl_async_signals(true);
        pcntl_alarm($timeout);
        try {
            return call_user_func_array($callable, $arguments);
        } finally {
            pcntl_alarm(0);
        }
    }
    public function canInvokeWithTimeout() : bool {
        return function_exists('pcntl_signal') && function_exists('pcntl_async_signals') && function_exists('pcntl_alarm');
    }

}

Members

Title Sort descending Modifiers Object type Summary
Invoker::$timeout private property
Invoker::canInvokeWithTimeout public function
Invoker::invoke public function
RSS feed
Powered by Drupal