bluestone/tree
Composer 安装命令:
composer require bluestone/tree
包简介
Build tree data structure
README 文档
README
Installation
This package requires php:^8.1.
You can install it via composer:
composer require bluestone/tree
Usage
Tree instance need items to forge the expected data structure.
How to forge a tree with array as items ?
By default, a tree expect id and parentId fields in give items like this :
use Bluestone\Tree\Tree; $items = [ ['id' => 1, 'parentId' => null, 'username' => 'Robert'], ['id' => 2, 'parentId' => 1, 'username' => 'John'], ['id' => 3, 'parentId' => 1, 'username' => 'Jane'], ]; $tree = new Tree($items); // Get Robert's children $robert = $tree->getNodeById(1); // Return the node representing Robert $robert->username; // Robert $robert->getChildren(); // Return an array containing John & Jane // Get Jane's parent $jane = $tree->getNodeById(3); $jane->getParent(); // Return Robert's node
How to forge a tree with custom fields ?
You can customize the parentKey and the primaryKey like this :
use Bluestone\Tree\Tree; $items = [ [ 'uuid' => 'b08f82b9-e8cc-44fb-b99a-4929bfcf02a4', 'parentUuid' => null, 'username' => 'Robert', ], [ 'uuid' => 'eaaf3215-17ba-4779-b444-d4a8203f1096', 'parentUuid' => 'b08f82b9-e8cc-44fb-b99a-4929bfcf02a4', 'username' => 'John', ], ]; $tree = new Tree($items, 'parentUuid', 'uuid');
How to serialize a tree to json ?
use Bluestone\Tree\Tree; $items = [ ['id' => 1, 'parentId' => null, 'name' => 'Chicken'], ['id' => 2, 'parentId' => 1, 'name' => 'Egg'], ]; $tree = new Tree($items); $json = json_encode($tree);
The result of the json_encode is a string with contains :
{
"primaryKey": "id",
"parentKey": "parentId",
"nodes": [
{"id": 1, "parentId": null, "name": "Chicken"},
{"id": 2, "parentId": 1, "name": "Egg"}
]
}
How to forge a tree with object as items ?
You can pass object as items with expected id and parentId public property like this :
use Tests\Artifacts\Person; use Bluestone\Tree\Tree; $items = [ new Person(1, null, 'Chicken'), new Person(2, 1, 'Egg'), ]; $tree = new Tree($items); $chicken = $tree->getNodeById(1); $chicken->name; // Chicken $chicken->getChildren(); // Return Egg's node
Contributing
Tree is an open source project under MIT License and is open for contributions.
bluestone/tree 适用场景与选型建议
bluestone/tree 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.8k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tree」 「data」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bluestone/tree 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bluestone/tree 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bluestone/tree 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
jsTree widget for yii2
Adds the EDTF data type to Wikibase
Doctrine2 behavior traits - slowhop fork
A simple library that allows transform any kind of data to native php data or whatever
A fast and dynamic Merkle tree implementation
统计信息
- 总下载量: 4.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-23