php-standard-library/os
Detect the operating system in a type-safe way using PHP Standard Library's OperatingSystemFamily enum. Part opf the php-standard-library project, this small package gives you a clean, enum-based API for OS detection instead of fragile string checks.
OperatingSystemFamily enum plus detection. The real decision isn't "which package," it's "do we accept a third-party dependency to avoid writing ~20 lines of php_uname()/PHP_OS_FAMILY parsing." Frame it that way in the ticket; it changes the answer.Linux, Windows, macOS, etc.) and what happens on anything else — WSL, FreeBSD, Alpine-in-Docker, AWS Lambda's environment. That artifact is more valuable than the code.str_contains(PHP_OS, 'WIN') checks with typed comparisons is a small, schedulable refactor with a clean definition of done. Good candidate for a maintenance sprint rather than a feature sprint.Adopt if all of these hold:
Look elsewhere — or just write it yourself — if:
PHP_OS_FAMILY is already in core PHP.php-standard-library/php-standard-library — evaluate that repo, not this one. If that's too much surface area for the benefit, write an internal helper class and own it.Recommendation as written: treat it as a convenience, not an architecture decision. Wrap it behind a single internal Platform service/facade rather than referencing the enum throughout the codebase. That keeps the exit cost near zero and gets you the type safety today.
To executives (one paragraph): "We have platform-specific behavior sprinkled through the code as string checks, which is where 'works on my machine' bugs come from. This is a tiny, MIT-licensed, zero-dependency PHP enum that makes 'which OS is this?' a typed value instead of a guess. It's not a strategic investment — it's a small consistency fix that makes cross-platform releases cheaper to support. Cost: one dependency and a short refactor. I'd approve it only if we're actually shipping to more than one platform."
To engineering (the actual argument): "It replaces str_contains(PHP_OS, 'WIN')-style checks with OperatingSystemFamily::current()->is(OperatingSystemFamily::WINDOWS) — typed, autocompleted, greppable, and testable by mocking one enum. It's additive, PHP 8.1+, no runtime cost. Two caveats we should own: (1) it's a micro-package with no community traction, so pin it and keep it behind our own Platform wrapper so we can drop it in an afternoon; (2) it detects family, not distro or WSL — if we need that, we design it ourselves on top. Suggested first step: land it in one CLI command, not a repo-wide refactor."
To the sceptical engineer in the room: "Yes, you could write this in twenty lines. That's a legitimate answer and I'd accept it. The case for the package is consistency and not re-litigating the edge cases in five places — not capability."
How can I help you explore Laravel packages today?