nujs2000 / 依赖图
一个用于在仓库中解析、可视化和验证 composer 依赖的 PHP 库。也适用于单体仓库。
v2.6.0
2024-01-18 06:50 UTC
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: 2024-09-18 08:48:08 UTC
README
此包可用于创建已使用包及其依赖关系的列表。
安装
使用 composer
composer require nusje2000/dependency-graph --dev
用法
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());
构建方法使用 3 个参数
- 根路径,这是您项目根目录的路径。
- 构建器,此类用于构建依赖图(留空为默认实现)。
- 缓存类,此类将用于缓存结果或从缓存中加载图。
可视化依赖关系
您可以使用 vendor/bin/dependency-graph search 来可视化依赖图。此控制台命令可用于在图中搜索并查看有关特定包的信息。此命令仍在开发中。
还有一个命令仅用于可视化包(不带搜索对话框)。例如,您可以使用 vendor/bin/dependency-graph info nusje2000/dependency-graph 来查看此包的依赖关系。
在单体仓库中验证依赖图
此包可用于检索单体仓库中定义的所有包。这已在 nusje2000/composer-monolith 包中的命令中实现,可用于在单体仓库中验证内部和外部依赖。
访问依赖图
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