Files
api/services/nginx/app/tests/Support/Api/ApiCleanup.php
T

34 lines
586 B
PHP

<?php
declare(strict_types=1);
namespace Tests\Support\Api;
use Closure;
use Throwable;
final class ApiCleanup
{
/**
* @var array<int, Closure():void>
*/
private array $callbacks = [];
public function add(Closure $callback): void
{
$this->callbacks[] = $callback;
}
public function run(): void
{
for ($index = count($this->callbacks) - 1; $index >= 0; $index--) {
try {
($this->callbacks[$index])();
} catch (Throwable) {
}
}
$this->callbacks = [];
}
}