nikaia/php-python-bridge

从 Php 调用您的 NodeJS 脚本

v1.0.0 2022-11-16 10:40 UTC

This package is auto-updated.

Last update: 2024-09-16 14:32:43 UTC


README

Latest Version on Packagist Tests

从 Php 调用您的 Python 脚本

安装

您可以通过 composer 安装此包

composer require nikaia/php-python-bridge

用法

该桥接器通过执行一个接受管道传输的 json 随意数据并返回 json 响应的 Python 脚本来工作。

查看 tests/_fixtures/ok.script.py 以获取一个工作示例。

use Nikaia\PythonBridge\Bridge;

try {
    $response = Bridge::create()
        ->setPython('/usr/local/bin/python')        // the path to the node (You can omit if in system path)
        ->setScript('/path/to/your/script.py')  // the path to your script 
        ->pipe(['foo' => 'bar'])                // the data to pipe to the script
        ->run();
}
catch (BridgeException $e) {
    echo $e->getMessage();
}

var_dump($response->json());   // ['foo' => 'bar']
var_dump($response->output()); // the raw output of the script {"foo":"bar"}

更新日志

请参阅 CHANGELOG 了解最近的变化信息。

版本发布

此包使用 semver 版本发布。版本发布由 standard-version Node 包管理,并需要遵循 conventionalcommit 提交风格。

  1. 实现一个功能或修复等。
  2. 使用类似 fix: Fix an issuefeat: Implement a feature ... 的提交信息
  3. 或者在合并/关闭 PR 时重写提交信息!
  4. 更新您的本地项目,检出 main 分支
  5. 运行: composer release 以生成更新日志并标记新版本。
  6. 检查一切是否正常。
  7. 使用 git push --follow-tags origin main 推送标签

此仓库正在使用 Semantic Pull Request bot 来强制执行常规提交信息和 PR 标题

鸣谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。