sweelix / tree
PHP 5.6+ 树结构管理
1.0.2
2016-03-22 08:25 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- php: >=5.6.0
- codeception/codeception: *
This package is not auto-updated.
Last update: 2024-09-22 00:36:05 UTC
README
Sweelix 节点管理是对 Dan Hazel 实现的有理数到键嵌套集合的扩展(http://arxiv.org/abs/0806.3115)。
安装
如果你使用 Packagist 安装包,那么你可以这样更新你的 composer.json:
{ "require": { "sweelix/tree": "*" } }
如何使用
创建一个 Node 类并将 NodeTrait 绑定到它。你可以查看 Node
类。
use sweelix\tree\NodeTrait; class MyNode { use NodeTrait; }
现在你可以创建一个节点
$node = new MyNode(); $node->setPath('1.2.1'); $leftBorder = $node->getLeft(); $rightBorder = $node->getRight(); $treeInfo = $node->getMatrix()->toArray(); // insert your node in DB using leftBorder and rightBorder // do not forget to also store the tree info
现在你可以使用常规嵌套集方法在你的数据库中搜索节点
# find all the children select * from nodes where left > :nodeLeft and right < :nodeRight order by nodeLeft; # find all the parents select * from nodes where left < :nodeLeft and right > :nodeRight order by nodeRight;
贡献
所有代码贡献 - 包括具有提交访问权限的人的贡献 - 必须通过拉取请求,并由核心开发者审核后才能合并。这是为了确保对所有代码的适当审查。
将项目分支出来,创建一个 功能分支,然后向我们发送一个拉取请求。