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