class ComposerExecutableValidator in Automatic Updates 8.2
Validates that the Composer executable can be found in the correct version.
Hierarchy
- class \Drupal\automatic_updates\Validator\ComposerExecutableValidator implements \PhpTuf\ComposerStager\Domain\Output\ProcessOutputCallbackInterface, \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of ComposerExecutableValidator
1 file declares its use of ComposerExecutableValidator
- ComposerExecutableValidatorTest.php in tests/
src/ Kernel/ ReadinessValidation/ ComposerExecutableValidatorTest.php
1 string reference to 'ComposerExecutableValidator'
1 service uses ComposerExecutableValidator
File
- src/
Validator/ ComposerExecutableValidator.php, line 19
Namespace
Drupal\automatic_updates\ValidatorView source
class ComposerExecutableValidator implements EventSubscriberInterface, ProcessOutputCallbackInterface {
use StringTranslationTrait;
/**
* The Composer runner.
*
* @var \PhpTuf\ComposerStager\Infrastructure\Process\Runner\ComposerRunnerInterface
*/
protected $composer;
/**
* The detected version of Composer.
*
* @var string
*/
protected $version;
/**
* Constructs a ComposerExecutableValidator object.
*
* @param \PhpTuf\ComposerStager\Infrastructure\Process\Runner\ComposerRunnerInterface $composer
* The Composer runner.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The translation service.
*/
public function __construct(ComposerRunnerInterface $composer, TranslationInterface $translation) {
$this->composer = $composer;
$this
->setStringTranslation($translation);
}
/**
* Validates that the Composer executable can be found.
*
* @param \Drupal\automatic_updates\Event\UpdateEvent $event
* The event object.
*/
public function checkForComposerExecutable(UpdateEvent $event) : void {
try {
$this->composer
->run([
'--version',
], $this);
} catch (ExceptionInterface $e) {
$error = ValidationResult::createError([
$e
->getMessage(),
]);
$event
->addValidationResult($error);
return;
}
if ($this->version) {
$major_version = ExtensionVersion::createFromVersionString($this->version)
->getMajorVersion();
if ($major_version < 2) {
$error = ValidationResult::createError([
$this
->t('Composer 2 or later is required, but version @version was detected.', [
'@version' => $this->version,
]),
]);
$event
->addValidationResult($error);
}
}
else {
$error = ValidationResult::createError([
$this
->t('The Composer version could not be detected.'),
]);
$event
->addValidationResult($error);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
AutomaticUpdatesEvents::READINESS_CHECK => 'checkForComposerExecutable',
];
}
/**
* {@inheritdoc}
*/
public function __invoke(string $type, string $buffer) : void {
$matched = [];
// Search for a semantic version number and optional stability flag.
if (preg_match('/([0-9]+\\.?){3}-?((alpha|beta|rc)[0-9]*)?/i', $buffer, $matched)) {
$this->version = $matched[0];
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ComposerExecutableValidator:: |
protected | property | The Composer runner. | |
ComposerExecutableValidator:: |
protected | property | The detected version of Composer. | |
ComposerExecutableValidator:: |
public | function | Validates that the Composer executable can be found. | |
ComposerExecutableValidator:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
ComposerExecutableValidator:: |
public | function | Constructs a ComposerExecutableValidator object. | |
ComposerExecutableValidator:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |