How to configure a composer package to be globally installed?

前端 未结 1 1580
无人及你
无人及你 2021-02-08 13:38

Update:

I actually published this package so you can see the problem for yourself.

Check it out here naomik/yamldump


I\'m trying t

1条回答
  •  逝去的感伤
    2021-02-08 14:27

    Targeting vendor/autoload.php is generally not a good idea and only works if you run the script from the correct directory. The following should serve you better:

    require_once __DIR__.'/../vendor/autoload.php';
    

    However, this still might be an issue if your application is installed as a dependency. In that case, you might need something more substantial:

    if (
        (!$classLoader = includeIfExists(__DIR__.'/../vendor/autoload.php')) &&
        (!$classLoader = includeIfExists(__DIR__.'/../../../autoload.php'))
    ) {
        echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
            'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
            'php composer.phar install'.PHP_EOL;
        exit(1);
    }
    

    This first looks for the autoloader in the location you would expect it to be if you are working directly on your application. If that does not exist, it looks where the autoloader would be if your application is installed as a dependency.

    0 讨论(0)
提交回复
热议问题