mirror of
https://github.com/stan220/testcontainers-php.git
synced 2026-09-09 02:29:31 +00:00
- 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 - ...
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user