mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-12 06:29:36 +00:00
initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Testcontainer;
|
||||
|
||||
use Testcontainer\Container\Container;
|
||||
|
||||
class Registry
|
||||
{
|
||||
private static bool $registeredCleanup = false;
|
||||
|
||||
/**
|
||||
* @var array<int|string, Container>
|
||||
*/
|
||||
private static array $registry = [];
|
||||
|
||||
public static function add(Container $container): void
|
||||
{
|
||||
self::$registry[spl_object_id($container)] = $container;
|
||||
|
||||
if (!self::$registeredCleanup) {
|
||||
register_shutdown_function([self::class, 'cleanup']);
|
||||
self::$registeredCleanup = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function remove(Container $container): void
|
||||
{
|
||||
unset(self::$registry[spl_object_id($container)]);
|
||||
}
|
||||
|
||||
public static function cleanup(): void
|
||||
{
|
||||
foreach (self::$registry as $container) {
|
||||
$container->remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user