maximaster/cli-ent

Guzzle 处理器,通过 CLI 模拟 HTTP 调用

dev-master 2020-12-26 15:07 UTC

This package is auto-updated.

Last update: 2024-09-26 23:17:21 UTC


README

Guzzle 处理器,通过 CLI 模拟 HTTP 调用。

原因

想象一下,你有一个只能通过 Web 界面安装的旧版 CMS。通过使用此处理器,你可以通过 CLI 仅调用所需的 HTTP 查询来安装这样的 CMS,就像通过 Web 界面一样,但无需运行 Web 服务器。

用法

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Guzzle\Parser\Cookie\CookieParser;
use Maximaster\CliEnt\CliEntHandler;
use Maximaster\CliEnt\GlobalsParser;
use Guzzle\Parser\Message\MessageParser;

$cliEntHandler = new CliEntHandler(
    new GlobalsParser(new CookieParser()),
    new MessageParser(),
    '/var/www',
    function (array &$globals) {
        // you can mofify global variables here before execution
        $globals['_ENV'] = ['a' => 'Lorem', 'b' => 'ipsum'];
        $globals['_SERVER']['DOCUMENT_ROOT'] = '/var/www';
    }
);

$client = new Client(['handler' => HandlerStack::create($cliEntHandler)]);
$response = $client->get('https:///install.php');
// etc

安装

composer require maximaster/cli-ent

但你也应该安装 runkit7,这将取决于你选择的版本,可能为 ext-runkit7ext-runkit

开发

你可以使用

  • make build - 准备
  • make test - 运行测试
  • make lint - 运行静态分析