承接 kappa/doctrine-mptt 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kappa/doctrine-mptt

Composer 安装命令:

composer require kappa/doctrine-mptt

包简介

Modified Pre-order Tree Traversal doctrine implementation

README 文档

README

Build Status

Modified Pre-order Tree Traversal doctrine implementation.

http://www.sitepoint.com/series/storing-hierarchical-data-in-a-database/

Requirements

Full list of dependencies you can get from Composer config file

Installation

The best way to install Kappa\DoctrineMPTT is using Composer

$ composer require kappa/doctrine-mptt:@dev

and register extension

extensions:
    doctrine: Kappa\Doctrine\DI\DoctrineExtension
    doctrineMPTT: Kappa\DoctrineMPTT\DI\DoctrineMPTTExtension

Benefits

  1. Minimize count of queries. For delete is needed 3 queries (1x DELETE, 2x UPDATE), for create is needed 3 queries (1x INSERT, 2x UPDATE) and for move item is needed only 1x UPDATE query. This algorithm is much faster and more fuel efficient than other commonly used methods, such as classical parent - children method.
  2. Full control over the nesting depth or count of branches

Restrictions and warnings

  1. This package was be tested on MySQL, SQLite and PostgreSQL and it is compatible with them
  2. Because this package is working directly with database to minimize count of queries after use moveItem() or insertItem() you should refresh loaded entities. Attention! you must save all updates before call this methods to avoids conflicts

Configuration

You can set custom names for used columns:

doctrineMPTT:
        entityClass: Your\entity
		originalLeftName: _lft
		leftColumnName: lft
		rightColumnName: rgt
		depthColumnName: depth

Configuration may not be in config file but can be set Kappa\DoctrineMPTT\TraversableManager::setConfigurator.

Usages

Package provide main Kappa\DoctrineMPTT\TraversableManager which can be used for all manipulations. All operations are performed over entity which is instance of Kappa\DoctrineMPTT\Entities\TraversableInterface.

Entity

You can use own entity but, your entity must implement Kappa\DoctrineMPTT\Entities\TraversableInterface interface. For easier implementation you can use Kappa\DoctrineMPTT\Entities\Traversable trait which implements all requires methods and columns.

Manager

Original tree structure

Original

Kappa\DoctrineMPTT\TraversableManager provides three methods by which we can do all operations.

Insert item

insertItem(TraversableInterface $actual, TraversableInterface $parent = null, $refresh)

Second argument is new parent and actual item (first argument) will be included under this parent item. Last argument is bool and if is set to true entities will be refreshed. For example: This code generate next tree

$parent = $this->repository->find(4);
$actual = new TraversableEntity();
// ....
$this->traversableManager->insertItem($parent, $actual);

After insert

If is parent null, actual item will be inserted as last child of root element if it exist. If not exist root element actual item will be inserted as root.

Move item

moveItem(TraversableInterface $actual, TraversableInterface $related, action, refresh)

With this method you can move each item into new place (as predecessor or descendant). Last argument is bool and if is set to true entities will be refreshed. For example predecessor

// (1)
$actual = $this->repository->find(3);
$related = $this->repository->find(2);
$this->traversableManager->moveItem($actual, $related, TraversableManager::PREDECESSOR); // (1) - move actual before related

// (2)
$actual = $this->repository->find(3);
$related = $this->repository->find(4);
$this->traversableManager->moveItem($actual, $related, TraversableManager::DESCENDANT); // (2) - move actual as child of related

// (3)
$actual = $this->repository->find(3);
$this->traversableManager->moveItem($actual, null, TraversableManager::DESCENDANT); // (3) - move actual as last child of root

(1) Result

After move predecessor

(2) Result

After move predecessor

(3) Result

After move predecessor

Remove item

removeItem(TraversableInterface $actual)

Remove item and all its children For example:

$actual = $this->repository->find(2);
$this->traversableManager->removeItem($actual);

After delete

Queries

  1. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetAll - returns all items sorted for scalable listing
  2. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetParents - returns all parents for actual item
  3. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetChildren - returns all children for actual item
  4. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetPrevious - return previous item
  5. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetNext - return next item
  6. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetParent - returns parent item
  7. Kappa\DoctrineMPTT\Queries\Objects\Selectors\GetRoot - returns tree root

You can use Kappa\DoctrineMPTT\Queries\SelectorsCollector as easier getter of query objects

kappa/doctrine-mptt 适用场景与选型建议

kappa/doctrine-mptt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 660 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「tree」 「doctrine」 「MPTT」 「traversal」 「Modified Pre-order Tree Traversal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kappa/doctrine-mptt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kappa/doctrine-mptt 我们能提供哪些服务?
定制开发 / 二次开发

基于 kappa/doctrine-mptt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 660
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-02-08