-
Notifications
You must be signed in to change notification settings - Fork 627
MDL-88576 [docs] Add documentation for Composer runtime status checks… #1612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,3 +47,60 @@ As far as there are a number of variables affecting how that lock file will be g | |
| 1. Check that the `composer.lock` file, together with other changes, does include the changes you've performed in the `composer.json` file. | ||
| 1. Ideally, run both phpunit and behat tests and verify that there isn't any problem, using all the supported PHP versions. | ||
| 1. Done, you can send the changes for review, integration and, if everything goes ok, will be applied upstream without problem. | ||
|
|
||
| ## Runtime status checks {/* #runtime-status-checks */} | ||
|
|
||
| Moodle provides a Composer runtime status API for inspecting the state of Composer-managed dependencies. | ||
|
|
||
| The API can be used to: | ||
|
|
||
| - Check whether Composer dependencies are installed. | ||
| - Verify that installed package versions match those recorded in `composer.lock`. | ||
| - Identify missing packages. | ||
| - Identify outdated packages. | ||
|
|
||
| ### Obtaining the service {/* #obtaining-the-service */} | ||
|
|
||
| ```php | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest adding a note here just to state that the service must be obtained using DI. Short single sentence is enough |
||
| $composer = \core\di::get(\core\composer::class); | ||
| ``` | ||
|
|
||
| ### Checking Composer installation status {/* #checking-composer-installation-status */} | ||
|
|
||
| To determine whether Composer dependencies are installed: | ||
|
|
||
| ```php | ||
| if ($composer->is_installed()) { | ||
| echo 'Composer dependencies are installed.'; | ||
| } | ||
| ``` | ||
|
|
||
| ### Retrieving overall status {/* #retrieving-overall-status */} | ||
|
|
||
| ```php | ||
| $status = $composer->get_status(); | ||
|
|
||
| if (!$status->installed) { | ||
| echo 'Composer dependencies are not installed.'; | ||
| } else if (!$status->current) { | ||
| echo 'One or more Composer packages require attention.'; | ||
| } | ||
| ``` | ||
|
|
||
| The `get_status()` method returns a `\core\composer\status` object containing the overall Composer runtime status and the status of all packages defined in `composer.lock`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this line above the code example. |
||
|
|
||
| The status object also provides convenience methods for identifying packages in a particular state: | ||
|
|
||
| ```php | ||
| $current = $status->current_packages(); | ||
| $missing = $status->missing_packages(); | ||
| $outdated = $status->outdated_packages(); | ||
| ``` | ||
|
|
||
| ### Checking a specific package {/* #checking-a-specific-package */} | ||
|
|
||
| ```php | ||
| $package = $composer->get_package_status('composer/installers'); | ||
| ``` | ||
|
|
||
| The `get_package_status()` method returns a `\core\composer\package_status` object containing information about the package's installation state and version information. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this line above the code example. Not sure if it's worth adding an example showing fetching the properties? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably needs a
<Since>tag