承接 netlogix/dependency-resolver 相关项目开发

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

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

netlogix/dependency-resolver

Composer 安装命令:

composer require netlogix/dependency-resolver

包简介

README 文档

README

The Task Graph Solver Package is a PHP library that provides a mechanism for resolving dependencies between tasks represented as a directed acyclic graph (DAG).

It helps you manage and execute tasks that are dependent on each other and ensures that the tasks are executed in the correct order to resolve their dependencies.

Installation

You can install this package using Composer:

composer require netlogix/task-graph-solver

Components

Task

You can use the simple Task implementation or create your own task based on the TaskInterface.

If you want to execute a task multiple times, you can implement the ResettableTaskInterface and reset the task to its initial state using the reset() method.

TaskPool

Tasks are managed by a TaskPool, you can use the bas TaskPool implementation or create your own TaskPool based on the TaskPoolInterface. The TaskPool is responsible for storing and providing access to your defined tasks.

TaskGraph

The TaskGraph class is used to resolve the task dependencies. It takes a TaskPool as input and can be iterated to get the tasks in the correct resolution order, considering their dependencies. It also checks for cyclic dependencies and prevents infinite loops.

Usage

use Netlogix\DependencyResolver\TaskGraph;

$taskGraph = new TaskGraph($taskPool);

foreach ($taskGraph as $resolutionBatch) {
        foreach ($resolutionBatch as $task) {
        // Execute the task or do any necessary operations.
        $task->resolve();
    }
}

Resetting Tasks

If your TaskPool implements the ResettableTaskPoolInterface, you can reset all tasks to their initial state for re-execution using the resetPool() method of the TaskGraph:

$taskGraph->resetPool();

Example

Here is a simple example that shows how to use the TaskGraph to resolve the dependencies between tasks and generate a mermaid state diagram.

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Netlogix\DependencyResolver\Task;
use Netlogix\DependencyResolver\TaskPool;
use Netlogix\DependencyResolver\TaskGraph;

$graph = new TaskGraph(
    new TaskPool([
        new Task('TaskA'),
        new Task('TaskB', ['TaskA']),
        new Task('TaskC', ['TaskA']),
        new Task('TaskD', ['TaskB', 'TaskC']),
        new Task('TaskE'),
    ])
);

$first=true;
$lines = ['stateDiagram'];
$lastTasks = [];
foreach ($graph->getIterator() as $tasks) {
    foreach ($tasks as $name => $task) {
        $lastTasks = array_filter($lastTasks, fn($t) => !in_array($t, $task->getDependencies()));
        array_push($lines, ...$first ? ["  [*] --> $name"]
            : array_map(fn($t) => "  $t --> $name", $task->getDependencies()));
        $lastTasks[$name] = $name;
        $task->resolve();
    }
    $first=false;
}
foreach ($lastTasks as $lastTask) {
    $lines[] = "  $lastTask --> [*]";
}

echo implode("\n", $lines) . "\n";

Result:

stateDiagram
    [*] --> TaskA
    [*] --> TaskE
    TaskA --> TaskB
    TaskA --> TaskC
    TaskB --> TaskD
    TaskC --> TaskD
    TaskE --> [*]
    TaskD --> [*]
Loading

netlogix/dependency-resolver 适用场景与选型建议

netlogix/dependency-resolver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.84k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 netlogix/dependency-resolver 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 23.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2023-11-06