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\InvokerView 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 |