PHPackages                             magnit56/dependency-graph - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. magnit56/dependency-graph

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

magnit56/dependency-graph
=========================

Dependency Graph Resolver in PHP

01.1k↓33.3%PHP

Since Sep 22Pushed 2y agoCompare

[ Source](https://github.com/magnit56/dependency-graph)[ Packagist](https://packagist.org/packages/magnit56/dependency-graph)[ RSS](/packages/magnit56-dependency-graph/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c72903445ecc266a9ce68d6f4d313f85bc99bb0f6ae6e0cb2b055ae0e484007a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646967696c6973742f646570656e64656e63792d67726170682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/digilist/dependency-graph/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/36e43fd528ccabda418de5c98feaefb331632c17e62864e09392cab5e1fb77bf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646967696c6973742f646570656e64656e63792d67726170682f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/digilist/dependency-graph/?branch=master)[![Build Status](https://camo.githubusercontent.com/746eed69765aaab7ce47595ebf08b54856878113752c20b78a5cac81a94df323/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646967696c6973742f646570656e64656e63792d67726170682f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/digilist/dependency-graph/build-status/master)

PHP DependencyGraph
===================

[](#php-dependencygraph)

This library provides a simple [Dependency Graph](http://en.wikipedia.org/wiki/Dependency_graph) resolver. It supports multiple root nodes which are detected automatically.

Installation
------------

[](#installation)

You can install this library with Composer by requiring `digilist/php-dependency-graph`

Example Usage:
--------------

[](#example-usage)

There are two ways to define dependencies. One way is to define the dependencies directly on the node by calling the `dependsOn` method. By using this method you have to add the nodes manually to the graph (or at least the root nodes).

```
$nodeA = new DependencyNode('A');
$nodeB = new DependencyNode('B');
$nodeC = new DependencyNode('C');
$nodeD = new DependencyNode('D');
$nodeE = new DependencyNode('E');

$nodeA->dependsOn($nodeB);
$nodeA->dependsOn($nodeD);
$nodeB->dependsOn($nodeC);
$nodeB->dependsOn($nodeE);
$nodeC->dependsOn($nodeD);
$nodeC->dependsOn($nodeE);

$graph = new DependencyGraph();
$graph->addNode($nodeA);
$resolved = DependencyGraph->resolve(); // returns [D, E, C, B, A]
```

Alternatively, you can define the dependencies on the graph. By using this method, the root node will be automatically detected.

```
$graph = new DependencyGraph();

$nodeA = new DependencyNode('A');
$nodeB = new DependencyNode('B');
$nodeC = new DependencyNode('C');
$nodeD = new DependencyNode('D');
$nodeE = new DependencyNode('E');

$graph->addDependency($nodeA, $nodeB);
$graph->addDependency($nodeA, $nodeD);
$graph->addDependency($nodeB, $nodeC);
$graph->addDependency($nodeB, $nodeE);
$graph->addDependency($nodeC, $nodeD);
$graph->addDependency($nodeC, $nodeE);

$resolved = DependencyGraph->resolve(); // returns [D, E, C, B, A]
```

The passed payload to DependencyNode can be any arbitrary PHP element (primitive, array, object, resource...).

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 58.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b91f6c3ed3b1aed8edccf4a2ec2369062bca555df8a259743ef8a6572022d09?d=identicon)[magnit56](/maintainers/magnit56)

---

Top Contributors

[![digilist](https://avatars.githubusercontent.com/u/833667?v=4)](https://github.com/digilist "digilist (7 commits)")[![jasir](https://avatars.githubusercontent.com/u/115066?v=4)](https://github.com/jasir "jasir (3 commits)")[![magnit56](https://avatars.githubusercontent.com/u/18706962?v=4)](https://github.com/magnit56 "magnit56 (2 commits)")

### Embed Badge

![Health badge](/badges/magnit56-dependency-graph/health.svg)

```
[![Health](https://phpackages.com/badges/magnit56-dependency-graph/health.svg)](https://phpackages.com/packages/magnit56-dependency-graph)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
