|
|
|
@ -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
|
|
|
|
|
<?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?
|
|
|
|
|
|
|
|
|
|
Packages managed entirely by Composer do not *need* to contain any
|
|
|
|
|