1
0
Fork 0

Add docs for the new bin-dir access and bump runtime-api, refs #10402

pull/10404/head
Jordi Boggiano 2021-12-28 22:04:22 +01:00
parent 6f5baab77b
commit a8ed352b31
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 44 additions and 1 deletions

View File

@ -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 by Composer's `vendor/autoload.php`, which would be useless as it would point back
to itself. 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) → ← [Config](06-config.md) | [Community](08-community.md) →

View File

@ -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 also require `"composer-runtime-api": "^2.2"` to ensure that the package
gets installed with a Composer version supporting the feature. 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
<?php
$binDir = $_composer_bin_dir ?? __DIR__ . '/../vendor/bin';
```
```php
#!/bin/bash
if [[ -z "$COMPOSER_BIN_DIR" ]]; then
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
else
BIN_DIR="$COMPOSER_BIN_DIR"
fi
```
If you want to rely on this in your package you should however make sure to
also require `"composer-runtime-api": "^2.2.2"` to ensure that the package
gets installed with a Composer version supporting the feature.
## What about Windows and .bat files? ## What about Windows and .bat files?
Packages managed entirely by Composer do not *need* to contain any Packages managed entirely by Composer do not *need* to contain any

View File

@ -66,7 +66,7 @@ class Composer
* *
* @var string * @var string
*/ */
const RUNTIME_API_VERSION = '2.2.0'; const RUNTIME_API_VERSION = '2.2.2';
/** /**
* @return string * @return string