Skip to content

Commit

Permalink
Merge pull request #3 from Fan2Shrek/add-docker
Browse files Browse the repository at this point in the history
Add Docker Support
  • Loading branch information
pyrech authored Oct 2, 2024
2 parents 527ff18 + 09efce0 commit 7062946
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
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

0 comments on commit 7062946

Please sign in to comment.