1
0
Fork 0

Document new methods and update the composer-runtime-api version to 2.1

pull/9699/head
Jordi Boggiano 2021-05-21 14:30:34 +02:00
parent 82cffa17d3
commit 284ec95712
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 38 additions and 1 deletions

View File

@ -27,6 +27,14 @@ The main use cases for this class are the following:
\Composer\InstalledVersions::isInstalled('psr/log-implementation'); // returns bool
```
As of Composer 2.1, you may also check if something was installed via require-dev or not by
passing false as second argument:
```php
\Composer\InstalledVersions::isInstalled('vendor/package'); // returns true assuming this package is installed
\Composer\InstalledVersions::isInstalled('vendor/package', false); // returns true if vendor/package is in require, false if in require-dev
```
Note that this can not be used to check whether platform packages are installed.
### Knowing whether package X is installed in version Y
@ -89,6 +97,35 @@ possible for safety.
A few other methods are available for more complex usages, please refer to the
source/docblocks of [the class itself](https://github.com/composer/composer/blob/master/src/Composer/InstalledVersions.php).
### Knowing the path in which a package is installed
The `getInstallPath` method to retrieve a package's absolute install path.
```php
// returns an absolute path to the package installation location if vendor/package is installed,
// or null if it is provided/replaced, or the package is a metapackage
// or throws OutOfBoundsException if the package is not installed at all
\Composer\InstalledVersions::getInstallPath('vendor/package');
```
> Available as of Composer 2.1 (i.e. `composer-runtime-api ^2.1`)
### Knowing which packages of a given type are installed
The `getInstalledPackagesByType` method accepts a package type (e.g. foo-plugin) and lists
the packages of that type which are installed. You can then use the methods above to retrieve
more information about each package if needed.
This method should alleviate the need for custom installers placing plugins in a specific path
instead of leaving them in the vendor dir. You can then find plugins to initialize at runtime
via InstalledVersions, including their paths via getInstallPath if needed.
```php
\Composer\InstalledVersions::getInstalledPackagesByType('foo-plugin');
```
> Available as of Composer 2.1 (i.e. `composer-runtime-api ^2.1`)
## Platform check
composer-runtime-api 2.0 introduced a new `vendor/composer/platform_check.php` file, which

View File

@ -65,7 +65,7 @@ class Composer
*
* @var string
*/
const RUNTIME_API_VERSION = '2.0.0';
const RUNTIME_API_VERSION = '2.1.0';
public static function getVersion()
{