drupal/plugin_topsort
Composer 安装命令:
composer require drupal/plugin_topsort
包简介
A mechanism for ordering plugin definitions using a directed acyclic graph.
README 文档
README
A mechanism for ordering plugin definitions using a directed acyclic graph.
It is intended for developers who are writing custom plugins, where the plugin definitions need to be "in order". Typically, these are plugins which transform data in some way, where the order of the transformations matters.
Usage
1. Add before/after properties to plugin definitions
A directed acyclic graph can be defined by way of before and after
properties in the plugin definition:
#[\Attribute(\Attribute::TARGET_CLASS)]
final class MyPlugin extends Plugin {
public function __construct(
string $id,
public readonly array $before = [],
public readonly array $after = [],
?string $deriver = NULL,
) {
parent::__construct($id, $deriver);
}
}
How to interpret these properties:
- A plugin's
beforeproperty can be thought of as "this plugin must run before the listed plugins". - A plugin's
afterproperty can be thought of as "this plugin must run after the listed plugins".
For example, the order of the following plugins may be enforced like this:
#[MyPlugin('first', before: ['second'])]
#[MyPlugin('second')]
#[MyPlugin('third', after: ['second'])]
You do not need to specify both before and after constraints to form
a dependency - either will suffice.
A LogicException is thrown if the constraints imply a circular dependency.
2. Add the trait to the plugin manager
- Use the
PluginManagerTopologicalSortTraitin your plugin manager:
use \Drupal\plugin_top_sort\PluginManagerTopologicalSortTrait;
class MyPluginManager extends DefaultPluginManager {
use PluginManagerTopologicalSortTrait;
...
}
The trait provides a findDefinitions() function that looks like this:
public function findDefinitions(): array {
$definitions = parent::findDefinitions();
// sort definitions
return $definitions;
}
Sorting happens after discovery, and after any alter hook has been called.
3. Plugin manager behavior.
The array returned by the plugin manager's getDefinitions() function
will be sorted in a way that respects the directed acyclic graph.
drupal/plugin_topsort 适用场景与选型建议
drupal/plugin_topsort 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 drupal/plugin_topsort 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drupal/plugin_topsort 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 69
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-05-10