morphql/morphql
Composer 安装命令:
composer require morphql/morphql
包简介
PHP wrapper for MorphQL — transform data with declarative queries
README 文档
README
A minimalist PHP wrapper for MorphQL — transform data with declarative queries.
PHP 5.6+ compatible · Bundled engine · Composer-ready
Installation
composer require morphql/morphql
Prerequisites
The package ships with the MorphQL engine pre-bundled. You have two options for execution:
- Node.js (Default): Requires Node.js v18+ installed on the system.
- QuickJS (Embedded): Self-contained, zero external dependencies. Binaries are automatically downloaded upon installation.
Quick Start
<?php require 'vendor/autoload.php'; use MorphQL\MorphQL; // One-shot transformation via CLI $result = MorphQL::execute( 'from json to json transform set greeting = "Hello, " + name', '{"name": "World"}' ); // → '{"greeting":"Hello, World"}'
Usage
Static API
// PHP 8+ with named parameters $result = MorphQL::execute( query: 'from json to json transform set x = a + b', data: '{"a": 1, "b": 2}' ); // PHP 5.6-7.x — single options array $result = MorphQL::execute(array( 'query' => 'from json to json transform set x = a + b', 'data' => '{"a": 1, "b": 2}', ));
Reusable Instance
// Preset defaults in the constructor $morph = new MorphQL(array( 'provider' => 'server', 'server_url' => 'http://localhost:3000', 'api_key' => 'my-secret', )); $result = $morph->run('from json to xml', $data); $other = $morph->run('from json to json transform set id = uuid', $data2);
Providers
| Provider | Backend | Transport | Runtime |
|---|---|---|---|
cli |
Bundled engine | proc_open() / shell |
node or qjs |
server |
MorphQL REST server | cURL / file_get_contents |
— |
The CLI provider auto-detects the bundled engine. By default, it uses Node.js, but it can be configured to use an embedded QuickJS runtime for a completely self-contained setup.
Node-less Runtime (QuickJS)
For a completely self-contained setup without Node.js, simply configure MorphQL to use the embedded QuickJS runtime:
$morph = new MorphQL(['runtime' => 'qjs']);
Tip
Automatic Installation: QuickJS binaries for your platform are automatically downloaded by Composer. If you need to reinstall them manually, run php bin/install-qjs.php.
Configuration
Options are resolved in priority order: call params → constructor → env vars → defaults.
| Option | Env Var | Default | Description |
|---|---|---|---|
provider |
MORPHQL_PROVIDER |
cli |
cli or server |
runtime |
MORPHQL_RUNTIME |
node |
node or qjs |
cli_path |
MORPHQL_CLI_PATH |
(auto) | Override CLI binary path |
node_path |
MORPHQL_NODE_PATH |
node |
Path to Node.js binary |
qjs_path |
MORPHQL_QJS_PATH |
(auto) | Path to QuickJS binary |
cache_dir |
MORPHQL_CACHE_DIR |
sys_get_temp_dir()/morphql |
CLI query cache dir |
server_url |
MORPHQL_SERVER_URL |
http://localhost:3000 |
Server base URL |
api_key |
MORPHQL_API_KEY |
(none) | API key for server auth |
timeout |
MORPHQL_TIMEOUT |
30 |
Timeout in seconds |
Environment Variables
export MORPHQL_PROVIDER=server export MORPHQL_SERVER_URL=http://my-morphql:3000 export MORPHQL_API_KEY=secret123
Error Handling
try { $result = MorphQL::execute('invalid query', '{}'); } catch (\RuntimeException $e) { echo 'Transform failed: ' . $e->getMessage(); } catch (\InvalidArgumentException $e) { echo 'Bad input: ' . $e->getMessage(); }
License
MIT © 2026 Hyperwindmill
morphql/morphql 适用场景与选型建议
morphql/morphql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「xml」 「csv」 「transform」 「edifact」 「data-transformation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 morphql/morphql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 morphql/morphql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 morphql/morphql 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
Load DOM document safety
laravel facade to read/write csv file
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 37
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-12