- 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:
Sergei Shitikov
2024-09-06 19:08:37 +02:00
parent a956794279
commit f05ea0020d
43 changed files with 1191 additions and 601 deletions
@@ -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;
}
}