mindplay/composer-locator
最新稳定版本:2.1.5
Composer 安装命令:
composer require mindplay/composer-locator
包简介
Locates Composer package root folders by package name
README 文档
README
⚠️ DEPRECATED: use Composer Runtime Utilities
This Composer plugin provides a means of locating the installation path for a given Composer package name.
Use this to locate vendor package roots, e.g. when working with template files or other assets in a package, locating and discovering plugins, and so on.
It works regardless of installers affecting the individual package installation paths, and also works whether the package in question is currently the root package/project or a dependency.
Usage
Add to your composer.json file:
{
"require": {
"mindplay/composer-locator": "^2"
},
"config": {
"allow-plugins": {
"mindplay/composer-locator": true
}
}
}
Running composer install or composer update will bootstrap your project with a generated class containing
a registry of Composer package installation paths.
To obtain the installation path for given package:
$path = ComposerLocator::getPath("vendor/package"); // => "/path/to/vendor/package"
If the specified package name is not found, the function throws a RuntimeException.
To check whether a given package is installed:
$is_installed = ComposerLocator::isInstalled("vendor/package"); // => (bool) true|false
The root Composer project package doesn't necessarily have a package name - to get the root path of the root Composer project, without specifying the package name:
$path = ComposerLocator::getRootPath(); // => "/path/to/project/root"
You can also get a list of all installed packages via ComposerLocator::getPackages(), or obtain a full
key/value map of package-names to absolute root paths via ComposerLocator::getPaths().
Why?
Needing to know the root path of a package installation folder is quite a common requirement, such as when you need to specify paths to template files or other assets.
The problem is that Composer itself offers no simple and reliable way to do that.
You can use reflection to get the path to a known class or interface from the package, and then dirname() up
from your src folder to the package installation root, but that approach isn't very robust, since the location
of a class file may change from one version to another.
Even if you know the path of the vendor root folder, and the {vendor}/{package} folder name convention, there
is no guarantee that's always where packages are installed - something like composer-installers
could affect the installation paths.
Also, when developing a library, during testing and development, the package will be installed as the root/project package, but this path will be different when it's installed as a dependency in another project.
mindplay/composer-locator 适用场景与选型建议
mindplay/composer-locator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 492.73k 次下载、GitHub Stars 达 58, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mindplay/composer-locator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mindplay/composer-locator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 492.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 59
- 点击次数: 18
- 依赖项目数: 21
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知