PHPackages                             netlogix/dependency-resolver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. netlogix/dependency-resolver

ActiveLibrary

netlogix/dependency-resolver
============================

1.1.0(1y ago)221.1k↓22.9%proprietaryPHPPHP  ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0CI passing

Since Nov 8Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/netlogix/task-graph-solver)[ Packagist](https://packagist.org/packages/netlogix/dependency-resolver)[ RSS](/packages/netlogix-dependency-resolver/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (5)Used By (0)

Task Graph Solver
=================

[](#task-graph-solver)

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
------------

[](#installation)

You can install this package using Composer:

```
composer require netlogix/task-graph-solver
```

Components
----------

[](#components)

### Task

[](#task)

You can use the simple [`Task`](src/Task.php) implementation or create your own task based on the [`TaskInterface`](src/TaskInterface.php).

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

### TaskPool

[](#taskpool)

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

### TaskGraph

[](#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
-----

[](#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

[](#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
-------

[](#example)

Here is a simple example that shows how to use the TaskGraph to resolve the dependencies between tasks and generate a [mermaid](https://mermaid.js.org/) state diagram.

```
