所有这一切都基于你实际上是在谈论包,而不是阶级(这是在提到的假设例如,但在问题中不要求)。
如果你有Composer
对象,你可以得到供应商目录从Config
对象的路径:
$vendorPath = $composer->getConfig()->get('vendor-dir');
$vendorPath
现在应该包含/home/me/public_html/vendor/
。
从那里构建其余的路径应该不会太困难,因为您已经拥有包名称。
如果这感觉太片状或者你不想写逻辑,还有另一种解决方案。你可以获取所有包,迭代,直到你找到正确的包抢从中路径:
$repositoryManager = $composer->getRepositoryManager();
$installationManager = $composer->getInstallationManager();
$localRepository = $repositoryManager->getLocalRepository();
$packages = $localRepository->getPackages();
foreach ($packages as $package) {
if ($package->getName() === 'willdurand/geocoder') {
$installPath = $installationManager->getInstallPath($package);
break;
}
}
$installPath
现在应该包含/home/me/public_html/vendor/willdurand/geocoder
不知道为什么你需要知道的文件路径。如果你只想自动加载课程,不要打扰。命令'php /path/to/composer.phar dump-autoload -o'将使用composer的自动加载器非常快地自动加载。 –