decodelabs/systemic

轻松访问系统和环境信息

v0.11.14 2024-08-21 20:41 UTC

README

PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

系统进程和信息触手可及

Systemic 提供了一个易于使用的界面,用于启动和控制系统进程以及访问系统信息。

DecodeLabs 博客上获取新闻和更新。

安装

通过 Composer 安装

composer require decodelabs/systemic

用法

导入

Systemic 使用 VeneerDecodeLabs\Systemic 下提供一个统一的界面。您可以通过这个静态界面访问所有主要功能,而不会影响测试和依赖注入。

进程启动

启动新进程

use DecodeLabs\Systemic;

$dir = 'path/to/working-directory';

// Launch and capture output of a process
echo Systemic::capture(['ls', '-al'], $dir)->getOutput();

// Launch and capture output of a process with raw string command (not escaped)
echo Systemic::capture('ls -al', $dir)->getOutput();

// Launch and capture output of a script
echo Systemic::capture(['myPhpScript.php'], $dir)->getOutput();

// Launch a background task
$process = Systemic::launch(['make', 'install']);

// Launch a background script
$process = Systemic::launchScript(['myPhpScript.php'], $dir);

// Run a piped pseudo terminal process
$success = Systemic::run(['interactive-app', '--arg1'], $dir);

// Run a piped pseudo terminal script
$success = Systemic::runScript(['myPhpScript.php', '--arg1'], $dir);

// Custom escaped command
$success = Systemic::command(['escaped', 'arguments'])
    ->setWorkingDirectory($dir)
    ->addSignal('SIGSTOP') // Pass SIGSTOP through when caught
    ->setUser('someuser') // Attempt to use sudo to run as user
    ->run();

// Custom raw command with env arguments
$result = Systemic::command('echo ${:VARIABLE} | unescaped-command', [
        'VARIABLE' => 'Hello world'
    ])
    ->setWorkingDirectory($dir)
    ->capture();

操作系统信息

获取当前操作系统的信息

use DecodeLabs\Systemic;

// OS info
echo Systemic::$os->getName(); // Linux | Windows | Darwin
echo Systemic::$os->getPlatformType(); // Unix | Windows
echo Systemic::$os->getDistribution(); // eg Ubuntu or High Sierra, etc
echo Systemic::$os->getVersion(); // System version info
echo Systemic::$os->getRelease(); // System version number
echo Systemic::$os->getHostName(); // System hostname

// Find binaries on the system
echo Systemic::$os->which('php'); // eg /usr/local/bin/php

Windows

请注意,Windows 上的操作系统和进程支持目前非常不稳定 - 这将在不久的将来完善!

区域设置 & 时区

寻找区域设置和时区信息?这已移至 Cosmos

许可

Systemic 使用 MIT 许可证。有关完整的许可证文本,请参阅 LICENSE