Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Plugin.php

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

Plugin

Namespace

Nevay\SPI\Composer

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal