-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathDockerContainerClient.php
More file actions
44 lines (36 loc) · 1.04 KB
/
DockerContainerClient.php
File metadata and controls
44 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
namespace Testcontainers\ContainerClient;
use Testcontainers\Docker\DockerClient;
class DockerContainerClient
{
/**
* @var DockerClient|null Singleton instance of DockerClient
*/
private static ?DockerClient $dockerClient = null;
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;
}
}