承接 phluxcp/operating-system 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phluxcp/operating-system

最新稳定版本:0.1.1

Composer 安装命令:

composer require phluxcp/operating-system

包简介

A PHP component to detect the running OS name, version and family.

README 文档

README

Phlux Control Panel logo

phluxcp/operating-system

A PHP framework-agnostic component to detect the running OS name, version and family. It can also be installed globally to use a binary to show your operating system.

Warning

This package is in early development stage and is not ready for production use. It is not tested yet, so use it at your own risk.

Installation

composer require phluxcp/operating-system

Usage

// Instance of Phlux\Component\OperatingSystem\System\SystemInterface
$system = Phlux\Component\OperatingSystem\detect();

Each OS instance class can (and should) extend a parent OS class if it is a derivative.

For example, you can detect if the running system is Ubuntu by checking the instance of the class:

use Phlux\Component\OperatingSystem;

$system = OperatingSystem\detect(); // Ubuntu instance
$system instanceof OperatingSystem\System\Ubuntu; // true

At the same time, you can check if you are running a Debian based OS, even if it is a derivated OS.

This can be very useful if you want to check between major Linux distributions:

use Phlux\Component\OperatingSystem;

$system = OperatingSystem\detect(); // Ubuntu instance

if ($system instanceof OperatingSystem\System\Debian) {
    // Do something if OS is Debian, Ubuntu, LMDE, Elementary...
} elseif ($system instanceof OperatingSystem\System\Fedora) {
    // Do something if OS is Fedora, RHEL, CentOS...
}

Adding new detectors

If you need to add a new detector for an obscure case, OS, or cannot wait for a pull request to get merged you can add more detectors when instantiating the Detector class:

use Phlux\Component\OperatingSystem;

// Create a new detector instance with custom detectors...

$detector = new OperatingSystem\Detector(
    new OperatingSystem\Filesystem\Amp(),
    [
        \MyNamespace\OperatingSystem\ObscureOS::class,
        // You can add detectors as you want if they all implements Phlux\Component\OperatingSystem\System\SystemInterface
    ],
);

// ...or add to the default detectors from the constructor...

$detector = new OperatingSystem\Detector(
    new OperatingSystem\Filesystem\Amp(),
    [
        ...OperatingSystem\Detector::DEFAULT_DETECTORS, // Include default detectors
        \MyNamespace\OperatingSystem\ObscureOS::class,
        // You can add detectors as you want if they all implements Phlux\Component\OperatingSystem\System\SystemInterface
    ],
);

// ...or add them later

$detector = new OperatingSystem\Detector(new OperatingSystem\Filesystem\Amp());
$detector->addSystem(\MyNamespace\OperatingSystem\ObscureOS::class);

Implement SystemInterface if the OS is not a derivated distribution...

use Phlux\Component\OperatingSystem\System\SystemInterface;
 
class ObscureOS implements SystemInterface
{
    // ...
}

...or just extend another OS

use Phlux\Component\OperatingSystem\System\Debian;

class ObscureOS extends Debian
{
    // ...
}

Binary usage

Besides phluxcp/operating-system is primarily intended to be programmatically used, it can be used to play as a binary in a global installation.

Simply run

composer global require phluxcp/operating-system

and run detect-operating-system

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-27