cycle/schema-renderer
Composer 安装命令:
composer require cycle/schema-renderer
包简介
Utils for Cycle ORM Schema rendering
README 文档
README
This package may be used to render Cycle ORM Schema in a terminal or generate php representation.
Installation
The preferred way to install this package is through Composer:
composer require cycle/schema-renderer
Example
Convert schema to array
$schema = new Schema([...]); $converter = new \Cycle\Schema\Renderer\SchemaToArrayConverter(); $schemaArray = $converter->convert($schema);
If passed SchemaInterface doesn't contain toArray() method then the SchemaToArrayConverter will convert
only common properties from Cycle\ORM\SchemaInterface. Null values will be skipped also.
In this case Iif you want to use custom properties you can pass them to the constructor
$converter = new \Cycle\Schema\Renderer\SchemaToArrayConverter(); $schemaArray = $converter->convert($schema, [ 42, CustomClass::CUSTOM_PROPERTY, ... ]);
Render schema to a terminal
use Cycle\Schema\Renderer\OutputSchemaRenderer; $output = new \Symfony\Component\Console\Output\ConsoleOutput(); $renderer = new OutputSchemaRenderer(colorize: true); $output->write($renderer->render($schemaArray));
By default, DefaultSchemaOutputRenderer renders in template only common properties and relations.
Custom properties will be rendered as is in separated block.
If you want to extend default rendering template you can create custom renderers and add them to the Output renderer.
use Cycle\Schema\Renderer\ConsoleRenderer\Renderer; use Cycle\Schema\Renderer\ConsoleRenderer\Formatter; use Cycle\Schema\Renderer\OutputSchemaRenderer; class CustomPropertyRenderer implements Renderer { public function render(Formatter $formatter, array $schema, string $role): string { $data = $schema['my_custom_property'] ?? null; return \sprintf( '%s: %s', $formatter->title($this->title), $data === null ? $formatter->error('not defined') : $formatter->typecast($data) ); } } $renderer = new OutputSchemaRenderer(); $renderer->addRenderer( new CustomPropertyRenderer(), new PropertyRenderer('my_custom_property', 'My super property') ); $output->write($renderer->render($schemaArray))
Store schema in a PHP file
use Cycle\Schema\Renderer\PhpSchemaRenderer; $path = __DIR__. '/schema.php' $renderer = new PhpSchemaRenderer(); \file_put_contents($path, $renderer->render($schemaArray));
The Renderer generates valid PHP code, in which constants from Cycle ORM classes are substituted for better readability.
License:
The MIT License (MIT). Please see LICENSE for more information.
Maintained by Spiral Scout.
cycle/schema-renderer 适用场景与选型建议
cycle/schema-renderer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 329.82k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2021 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cycle/schema-renderer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cycle/schema-renderer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 329.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 28
- 依赖项目数: 11
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-01