Skip to content

Commit 09efce0

Browse files
committed
Add Docker Support
1 parent 527ff18 commit 09efce0

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Not released yet
44

55
* Remove mb_string extension requirement
6+
* Add Docker support
67

78
## 0.1.0 (2023-12-03)
89

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ OsHelper::isWindowsSeven(); // true or false
2121
OsHelper::isWindowsEightOrHigher(); // true or false
2222
OsHelper::isWindowsSubsystemForLinux(); // true or false
2323
OsHelper::isMacOs(); // true or false
24+
OsHelper::isDocker(); // true or false
2425
OsHelper::getMacOSVersion(); // 10.15.7
2526
```
2627

src/OsHelper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static function isUnix(): bool
1515

1616
public static function isWindowsSubsystemForLinux(): bool
1717
{
18-
return self::isUnix() && str_contains(strtolower(php_uname()), 'microsoft');
18+
return !self::isDocker() && self::isUnix() && str_contains(strtolower(php_uname()), 'microsoft');
1919
}
2020

2121
public static function isWindows(): bool
@@ -50,6 +50,11 @@ public static function isMacOS(): bool
5050
return str_contains(self::$kernelName, 'Darwin');
5151
}
5252

53+
public static function isDocker(): bool
54+
{
55+
return file_exists('/.dockerenv') || (file_exists('/proc/self/cgroup') && false !== mb_strpos(file_get_contents('/proc/self/cgroup') ?: '', 'docker'));
56+
}
57+
5358
public static function getMacOSVersion(): string
5459
{
5560
if (!isset(self::$macOSVersion)) {

tests/OsHelperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public function testIsMacOS()
6565
$this->assertSame($isDarwin, OsHelper::isMacOS());
6666
}
6767

68+
public function testIsDocker()
69+
{
70+
$isDocker = file_exists('/.dockerenv') || (file_exists('/proc/self/cgroup') && false !== mb_strpos(file_get_contents('/proc/self/cgroup') ?: '', 'docker'));
71+
72+
$this->assertSame($isDocker, OsHelper::isDocker());
73+
}
74+
6875
public function testGetMacOSVersion()
6976
{
7077
if (!OsHelper::isMacOS()) {

0 commit comments

Comments
 (0)