Get filesystem path of installed composer package

后端 未结 4 1097
渐次进展
渐次进展 2021-02-08 07:43

How can get filesystem path of composer package?

composer.json example:

{

    \"require\" : {
        \"codeception/codeception\" : \"@stable\",
                


        
4条回答
  •  没有蜡笔的小新
    2021-02-08 08:02

    Try ReflectionClass::getFileName - Gets the filename of the file in which the class has been defined. http://www.php.net/manual/en/reflectionclass.getfilename.php

    Example:

    $reflector = new ReflectionClass("\Geocoder\HttpAdapter\HttpAdapterInterface");
    echo $reflector->getFileName();
    

    Or you may use this:

    $loader = require './vendor/autoload.php';
    echo $loader->findFile("\Geocoder\HttpAdapter\HttpAdapterInterface");
    

    The first method try to load class and return loaded class path. The second method return path from composer database without class autoload.

提交回复
热议问题