Files
testcontainers-php/src/ContainerClient/DockerContainerClient.php
T
Sergei Shitikov f05ea0020d - Move most of the stuff for backwards compatibility support into one class
- Added random port logic
- Updated wait wtrategies
- API alignments to make it similar to other official implementations
- ...
2024-09-06 19:08:37 +02:00

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;
}
}