Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker Support #3

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Not released yet

* Remove mb_string extension requirement
* Add Docker support

## 0.1.0 (2023-12-03)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ OsHelper::isWindowsSeven(); // true or false
OsHelper::isWindowsEightOrHigher(); // true or false
OsHelper::isWindowsSubsystemForLinux(); // true or false
OsHelper::isMacOs(); // true or false
OsHelper::isDocker(); // true or false
OsHelper::getMacOSVersion(); // 10.15.7
```

Expand Down
7 changes: 6 additions & 1 deletion src/OsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function isUnix(): bool

public static function isWindowsSubsystemForLinux(): bool
{
return self::isUnix() && str_contains(strtolower(php_uname()), 'microsoft');
return !self::isDocker() && self::isUnix() && str_contains(strtolower(php_uname()), 'microsoft');
}

public static function isWindows(): bool
Expand Down Expand Up @@ -50,6 +50,11 @@ public static function isMacOS(): bool
return str_contains(self::$kernelName, 'Darwin');
}

public static function isDocker(): bool
{
return file_exists('/.dockerenv') || (file_exists('/proc/self/cgroup') && false !== mb_strpos(file_get_contents('/proc/self/cgroup') ?: '', 'docker'));
}

public static function getMacOSVersion(): string
{
if (!isset(self::$macOSVersion)) {
Expand Down
7 changes: 7 additions & 0 deletions tests/OsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public function testIsMacOS()
$this->assertSame($isDarwin, OsHelper::isMacOS());
}

public function testIsDocker()
{
$isDocker = file_exists('/.dockerenv') || (file_exists('/proc/self/cgroup') && false !== mb_strpos(file_get_contents('/proc/self/cgroup') ?: '', 'docker'));

$this->assertSame($isDocker, OsHelper::isDocker());
}

public function testGetMacOSVersion()
{
if (!OsHelper::isMacOS()) {
Expand Down
Loading