mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-08 17:29:29 +00:00
- Added random port logic - Updated wait wtrategies - API alignments to make it similar to other official implementations - ...
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Testcontainers\ContainerClient;
|
|
|
|
use Docker\Docker as DockerClient;
|
|
|
|
class DockerContainerClient
|
|
{
|
|
/**
|
|
* @var DockerClient|null Singleton instance of DockerClient
|
|
*/
|
|
private static ?DockerClient $dockerClient = null;
|
|
|
|
/**
|
|
* Private constructor to prevent creating instance outside the class.
|
|
*/
|
|
private function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Returns the singleton DockerClient instance.
|
|
*
|
|
* @return DockerClient The singleton DockerClient instance.
|
|
* @throws \RuntimeException If the DockerClient instance could not be created.
|
|
*/
|
|
public static function getDockerClient(): DockerClient
|
|
{
|
|
if (self::$dockerClient === null) {
|
|
self::$dockerClient = DockerClient::create();
|
|
}
|
|
|
|
return self::$dockerClient;
|
|
}
|
|
|
|
/**
|
|
* Injects a DockerClient instance for testing or special use cases.
|
|
*
|
|
* @param DockerClient $client The DockerClient instance to set.
|
|
*/
|
|
public static function setDockerClient(DockerClient $client): void
|
|
{
|
|
self::$dockerClient = $client;
|
|
}
|
|
}
|