The OS Info component provides a robust and flexible way to detect and work with operating system information in your applications. It offers a comprehensive set of features for identifying operating systems, their families, and supported standards.
Installation
Requirements:
PHP ^8.4
ext-ffi (optional, provides more detailed and accurate information about the OS)
ext-com_dotnet (optional, provides more detailed and accurate information about the OS)
Family: Darwin
Name: Darwin
Version: 24.4.0
Codename: ~
Edition: ~
Standards: POSIX
OS Families
You can get the OS family information from the OS information object ($os->family). However, if you do not need all the OS information, it is enough to get the family separately using the Family::createFromGlobals() method.
use Boson\Component\OsInfo\Family;
// Get current OS family
$family = Family::createFromGlobals();
// Strict compliance
if ($family === Family::BSD) {
// Only BSD OS
}
// Compatibility check
if ($family->is(Family::BSD)) {
// BSD and BSD-like, for example:
// - BSD
// - Solaris
// - Darwin (macOS)
// - etc
}
Please note that the $family->is() check includes the check of the family itself and its parents.
if ($family->is(Family::Unix)) {
// All operating systems from the Unix family
// will be subject to this check:
// - Darwin (macOS)
// - Linux
// - BSD
// - ...and other Unix-like
}
Standards Support
use Boson\Component\OsInfo\OperatingSystem;
use Boson\Component\OsInfo\Standard;
$os = OperatingSystem::createFromGlobals();
// Check if OS supports a specific standard
if ($os->isSupports(Standard::Posix)) {
// Standard is supported
}