1
0
Fork 0

Add one more use case to InstalledVersions docs

pull/8880/head
Jordi Boggiano 2020-05-06 11:12:25 +02:00
parent ba3df8faea
commit 592b05df11
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 14 additions and 0 deletions

View File

@ -72,6 +72,20 @@ package.
\Composer\InstalledVersions::getReference('vendor/package'); \Composer\InstalledVersions::getReference('vendor/package');
``` ```
### Knowing a package's own installed version
If you are only interested in getting a package's own version, e.g. in the source of acme/foo you want
to know which version acme/foo is currently running to display that to the user, then it is
acceptable to use getVersion/getPrettyVersion/getReference.
The warning in the section above does not apply in this case as you are sure the package is present
and not being replaced if your code is running.
It is nonetheless a good idea to make sure you handle the `null` return value as gracefully as
possible for safety.
----
A few other methods are available for more complex usages, please refer to the A few other methods are available for more complex usages, please refer to the
source/docblocks of the class itself. source/docblocks of the class itself.