nusje2000 / dependency-graph
A PHP Library for resolving, visualizing and validating composer dependencies within a repository. Works within a monolithic repository as well.
Installs: 26 959
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 3
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- aeviiq/collection: ^3.1 || ^4.0
- myclabs/php-enum: ^1.7
- symfony/console: ^4.4|^5.0|^6.0
- symfony/finder: ^4.4|^5.0|^6.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2025-03-18 10:05:19 UTC
README
This package can be used to create a list of used packages and their dependencies.
Installation
Using composer:
composer require nusje2000/dependency-graph --dev
Usage
use Nusje2000\DependencyGraph\Cache\FileCache; use Nusje2000\DependencyGraph\DependencyGraph; // By default the DependencyGraph won't cache the result $graph = DependencyGraph::build('/path/to/project/root'); // Using the FileCache to cache the dependency graph $graph = DependencyGraph::build('/path/to/project/root', null, new FileCache());
The build method uses 3 parameters:
- The root path, this is the path to the root of your project.
- The builder, this class is used to build the dependency graph (leave null for default implementation).
- The cache class, this class will be used to cache the result or to load the graph from if a cache exists.
Visualizing dependencies
You can visualize the dependency graph by using vendor/bin/dependency-graph search
.
This console command can be used to search through the graph and look at
information about certain packages. This command is still being worked on.
There is also a command for only visualizing a package (without the
search dialog). i.e. you can use vendor/bin/dependency-graph info nusje2000/dependency-graph
to see the dependencies of this package.
Validating the dependency graph in monolithic repositories
This package can be used to fetch all the packages defined in monolithic
repositories. This has been implemented into a command in the
nusje2000/composer-monolith
package, which can be used to validate
internal and external dependencies in a monolithic repository.
Accessing the dependency graph
use Nusje2000\DependencyGraph\DependencyGraph; // building the dependency graph $graph = DependencyGraph::build('/path/to/project/root'); // get the root path $graph->getRootPath(); // get all packages $packages = $graph->getPackages(); // checking if a package exists $graph->hasPackage('foo/foo-pacakge'); // getting a specific package $fooPackage = $graph->getPackage('foo/foo-pacakge'); $fooPackage->getName(); // return the name of the package (foo/foo-pacakge) $fooPackage->getDependencies(); // returns a list of dependencies $fooPackage->getPackageLocation(); // returns the location of the package