Get filesystem path of installed composer package

Asked
Active3 hr before
Viewed126 times

2 Answers

installed
90%

If you have the Composer object, you can get the path of the vendor directory from the Config object:,$vendorPath should now contain /home/me/public_html/vendor/. ,$installPath should now contain /home/me/public_html/vendor/willdurand/geocoder,If this feels too flaky or you don't want to write the logic, there is another solution. You could fetch all packages, iterate until you find the right package and grab the path from it:

If you have the Composer object, you can get the path of the vendor directory from the Config object:

    $vendorPath = $composer - > getConfig() - > get('vendor-dir');

If this feels too flaky or you don't want to write the logic, there is another solution. You could fetch all packages, iterate until you find the right package and grab the path from it:

    $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;
       }
    }
load more v
88%

Each framework may have one or many different required package installation paths. Composer can be configured to install packages to a folder other than the default vendor folder by using composer/installers.,Now when your theme is installed with Composer it will be placed into wp-content/themes/themename/ folder. Check the current supported types for your package., Composer and all content on this site are released under the MIT license. ,Note: You cannot use this to change the path of any package. This is only applicable to packages that require composer/installers and use a custom type that it handles.

If you are a package author and want your package installed to a custom directory, require composer/installers and set the appropriate type. Specifying the package type, will override the default installer path. This is common if your package is intended for a specific framework such as CakePHP, Drupal or WordPress. Here is an example composer.json file for a WordPress theme:

{
   "name": "you/themename",
   "type": "wordpress-theme",
   "require": {
      "composer/installers": "~1.0"
   }
}
load more v

Other "installed-undefined" queries related to "Get filesystem path of installed composer package"