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

Breadcrumb

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

function ContainerBuilder::willBeAvailable

Checks whether a class is available and will remain available in the "no-dev" mode of Composer.

When parent packages are provided and if any of them is in dev-only mode, the class will be considered available even if it is also in dev-only mode.

Throws

\LogicException If dependencies have been installed with Composer 1

File

vendor/symfony/dependency-injection/ContainerBuilder.php, line 1570

Class

ContainerBuilder
ContainerBuilder is a DI container that provides an API to easily describe services.

Namespace

Symfony\Component\DependencyInjection

Code

public static final function willBeAvailable(string $package, string $class, array $parentPackages) : bool {
    if (!class_exists(InstalledVersions::class)) {
        throw new \LogicException(\sprintf('Calling "%s" when dependencies have been installed with Composer 1 is not supported. Consider upgrading to Composer 2.', __METHOD__));
    }
    if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
        return false;
    }
    if (!InstalledVersions::isInstalled($package) || InstalledVersions::isInstalled($package, false)) {
        return true;
    }
    // the package is installed but in dev-mode only, check if this applies to one of the parent packages too
    $rootPackage = InstalledVersions::getRootPackage()['name'] ?? '';
    if ('symfony/symfony' === $rootPackage) {
        return true;
    }
    foreach ($parentPackages as $parentPackage) {
        if ($rootPackage === $parentPackage || InstalledVersions::isInstalled($parentPackage) && !InstalledVersions::isInstalled($parentPackage, false)) {
            return true;
        }
    }
    return false;
}

API Navigation

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