Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions general/development/tools/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}

Copy link
Copy Markdown
Member

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Loading