diff --git a/doc/07-runtime.md b/doc/07-runtime.md index f4d4c8da4..fef0b3923 100644 --- a/doc/07-runtime.md +++ b/doc/07-runtime.md @@ -162,4 +162,13 @@ This is set by the binary proxy and as such is not made available to projects by Composer's `vendor/autoload.php`, which would be useless as it would point back to itself. +## Binary (bin-dir) path in binaries + +composer-runtime-api 2.2.2 introduced a new `$_composer_bin_dir` global +variable set when running binaries installed with Composer. Read more +about this [on the vendor binaries docs](articles/vendor-binaries.md#finding-the-composer-bin-dir-from-a-binary). + +This is set by the binary proxy and as such is not made available to projects +by Composer's `vendor/autoload.php`. + ← [Config](06-config.md) | [Community](08-community.md) → diff --git a/doc/articles/vendor-binaries.md b/doc/articles/vendor-binaries.md index 120b73dec..f55c92692 100644 --- a/doc/articles/vendor-binaries.md +++ b/doc/articles/vendor-binaries.md @@ -93,6 +93,40 @@ If you want to rely on this in your package you should however make sure to also require `"composer-runtime-api": "^2.2"` to ensure that the package gets installed with a Composer version supporting the feature. +## Finding the Composer bin-dir from a binary + +As of Composer 2.2.2, a new `$_composer_bin_dir` global variable +is defined by the bin proxy file, so that when your binary gets executed +it can use it to easily locate the project's autoloader. + +For non-PHP binaries, the bin proxy sets a `COMPOSER_BIN_DIR` environment +variable. + +This global variable will not be available however when running binaries defined +by the root package itself, so you need to have a fallback in place. + +This can look like this for example: + +```php +