function Plugin::providerRuntimeValidatedRequirements
1 call to Plugin::providerRuntimeValidatedRequirements()
- Plugin::dumpGeneratedServiceProviderData in vendor/
tbachert/ spi/ src/ Composer/ Plugin.php
File
-
vendor/
tbachert/ spi/ src/ Composer/ Plugin.php, line 152
Class
Namespace
Nevay\SPI\ComposerCode
private static function providerRuntimeValidatedRequirements(string $provider) : ?string {
// The current implementation is suboptimal if multiple runtime validated requirements are specified
// - should check all hashes of not satisfied requirements before calling ::isSatisfied()
// - should deduplicate requirements
$condition = var_export(true, true);
/** @var ReflectionAttribute<ServiceProviderRequirementRuntimeValidated> $attribute */
foreach ((new ReflectionClass($provider))->getAttributes(ServiceProviderRequirementRuntimeValidated::class, ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
$requirement = $attribute->newInstance();
$class = '\\' . $requirement::class;
$args = '';
foreach ($attribute->getArguments() as $key => $value) {
$args and $args .= ', ';
if (is_string($key)) {
$args .= $key;
$args .= ': ';
}
$args .= var_export($value, true);
}
$hash = var_export($requirement->hash(), true);
$condition .= $requirement->isSatisfied() ? " && ((\$r = new {$class}({$args}))->hash() === {$hash} || \$r->isSatisfied())" : " && ((\$r = new {$class}({$args}))->hash() !== {$hash} && \$r->isSatisfied())";
}
if (!isset($requirement)) {
return null;
}
return $condition;
}