Get filesystem path of installed composer package

后端 未结 4 1103
渐次进展
渐次进展 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:17

    Not sure if the following is the correct way for this because composer is changing so fast.

    If you run this command:

    php /path/to/composer.phar dump-autoload -o
    

    it will create a classmap array in this file

    vender/composer/autoload_classmap.php
    

    with this format "classname" => filepath.

    So to find filepath of a given class is simple. If you create the script in your project's root folder, you can do this:

    $classmap = require('vender/composer/autoload_classmap.php');
    $filepath = $classmap[$classname]?: null;
    

提交回复
热议问题