package_manager.install

File

core/modules/package_manager/package_manager.install

View source
<?php


/**
 * @file
 * Contains install and update functions for Package Manager.
 */
declare (strict_types=1);
use Drupal\package_manager\ComposerInspector;
use Drupal\package_manager\Exception\StageFailureMarkerException;
use Drupal\package_manager\FailureMarker;
use PhpTuf\ComposerStager\API\Exception\ExceptionInterface;
use PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface;

/**
 * Implements hook_requirements().
 */
function package_manager_requirements(string $phase) : array {
    $requirements = [];
    // If we're able to check for the presence of the failure marker at all, do it
    // irrespective of the current run phase. If the failure marker is there, the
    // site is in an indeterminate state and should be restored from backup ASAP.
    $service_id = FailureMarker::class;
    if (\Drupal::hasService($service_id)) {
        try {
            \Drupal::service($service_id)->assertNotExists(NULL);
        } catch (StageFailureMarkerException $exception) {
            $requirements['package_manager_failure_marker'] = [
                'title' => t('Failed Package Manager update detected'),
                'description' => $exception->getMessage(),
                'severity' => REQUIREMENT_ERROR,
            ];
        }
    }
    if ($phase !== 'runtime') {
        return $requirements;
    }
    
    /** @var \PhpTuf\ComposerStager\API\Finder\Service\ExecutableFinderInterface $executable_finder */
    $executable_finder = \Drupal::service(ExecutableFinderInterface::class);
    // Report the Composer version in use, as well as its path.
    $title = t('Composer version');
    try {
        $requirements['package_manager_composer'] = [
            'title' => $title,
            'description' => t('@version (<code>@path</code>)', [
                '@version' => \Drupal::service(ComposerInspector::class)->getVersion(),
                '@path' => $executable_finder->find('composer'),
            ]),
            'severity' => REQUIREMENT_INFO,
        ];
    } catch (\Throwable $e) {
        // All Composer Stager exceptions are translatable.
        $message = $e instanceof ExceptionInterface ? $e->getTranslatableMessage() : $e->getMessage();
        $requirements['package_manager_composer'] = [
            'title' => $title,
            'description' => t('Composer was not found. The error message was: @message', [
                '@message' => $message,
            ]),
            'severity' => REQUIREMENT_ERROR,
        ];
    }
    return $requirements;
}

Functions

Title Deprecated Summary
package_manager_requirements Implements hook_requirements().

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.