hellonico / guzzle-cli-handler
Guzzle CLI 处理器,用于模拟通过 CLI 进行 HTTP 请求
0.1.0
2021-05-06 12:08 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.2 || ^7.2
- guzzlehttp/promises: ^1.3
- guzzlehttp/psr7: ^1.6
- psr/http-message: ^1.0
- symfony/http-foundation: ^5.2
- symfony/process: ^5.0
Requires (Dev)
- phpstan/phpstan: ^0.12.83
- phpunit/phpunit: ^8.5 || ^9.0
- symplify/easy-coding-standard: ^9.2
README
Guzzle 处理器,通过 CLI 模拟 HTTP 请求。
动机
执行请求而无需运行 Web 服务器。
用法
use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use HelloNico\GuzzleCliHandler\CliHandler; // Document root $docRoot = '/var/www'; // File path // - If absolute, will directly use $filePath // - If relative, will be `$docRoot . DIRECTORY_SEPARATOR . $filePath` // - If URL requested ends with .php, will be overrided and set to `$docRoot . DIRECTORY_SEPARATOR . $urlPath` $filePath = 'index.php'; $cliHandler = new CliHandler( $docRoot, $filePath, function (array &$globals) { // you can mofify global variables here before execution $globals['_ENV'] = ['a' => 'Lorem', 'b' => 'ipsum']; } ); $client = new Client(['handler' => HandlerStack::create($cliHandler)]); $response = $client->get('http://localhost/install.php');
安装
composer require hellonico/guzzle-cli-handler
限制
由于 PHP 在 CLI 中运行,很遗憾无法获取响应头并维护会话。
开发
composer test
- 运行 phpunitcomposer analyse
- 运行 phpstancomposer lint
- 运行 ecs(编码规范)