ballen / executioner
Executioner 是一个 PHP 库,用于执行系统进程和应用程序,并能够传递额外参数以及读取 CLI 输出结果。
Requires
- php: >=7.3.0
- ballen/collection: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-25 04:22:42 UTC
README
Executioner 是一个 PHP 库,用于执行系统进程和应用程序,并能够传递额外参数以及读取 CLI 输出结果。
需求
此库已通过 PHP 7.3、7.4、8.0、8.1 和 8.2 进行单元测试!
如果您需要使用旧版本的 PHP,您应安装此库的 3.x 版本(以下将提供详细信息)。
许可证
此客户端库在 MIT 许可证下发布,此包中提供了许可证副本[点击查看]。
安装
要将此包安装到您的项目中(假设您正在使用 Composer 包管理器),您只需从您的项目文件夹根目录的终端中执行以下命令
composer require ballen/executioner
如果您需要使用旧版本的 PHP,版本 3.x.x 支持 PHP 5.3、5.4、5.5、5.6、7.0、7.1 和 7.2,您可以使用此命令安装此版本
composer require ballen/executioner ^3.0
使用示例
获取服务器 IP 地址信息的示例。
use Ballen\Executioner\Executioner; $run = new Executioner(); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $run->setApplication('ipconfig'); // Server is Microsoft Windows! } else { $run->sudo() // Lets assume we must run 'sudo' to get the output... ->setApplication('ifconfig'); } $run->execute(); // We'll simply just display the results as a plain text string... echo $run->resultAsText();
使用终端命令 php -v
获取 PHP 版本号的示例。
use Ballen\Executioner\Executioner; /** * A shorthand version of using the factory method to create a new instance * and then chaining the other methods and getting the response. */ $php_version = Executioner::make('php') ->addArgument('-v') ->execute() ->resultAsArray(); $words = explode(' ', $php_version[0]); // Split the words from the first line of the output! $extracted_version_number = $words[1]; // The second word in the raw outputted line should be the version number :) echo 'The extacted version number is: ' . $extracted_version_number . ''; // The extacted version number is: 7.0.0
这些示例也可以在 examples 目录中找到。
测试和覆盖率
此库使用 PHPUnit 进行完全单元测试。
我使用 GitHub Actions 进行持续集成,每次提交都会触发 PHP 7.3、7.4、8.0、8.1 和 8.2 的测试。
如果您想自己运行测试,应运行以下命令
# Install the Cartographer Library (which will include PHPUnit as part of the require-dev dependencies) composer install # Now we run the unit tests (from the root of the project) like so: ./vendor/bin/phpunit
还可以运行代码覆盖率,并生成报告(这需要安装 XDebug)...
./vendor/bin/phpunit --coverage-html ./report
支持
我很乐意通过我的个人电子邮件地址提供支持,因此如果您需要帮助,请发邮件至:ballen@bobbyallen.me。