function PhpFileLoader::configBuilder
Parameters
string $namespace FQCN string for a class implementing ConfigBuilderInterface:
1 call to PhpFileLoader::configBuilder()
- PhpFileLoader::executeCallback in vendor/
symfony/ dependency-injection/ Loader/ PhpFileLoader.php - Resolve the parameters to the $callback and execute it.
File
-
vendor/
symfony/ dependency-injection/ Loader/ PhpFileLoader.php, line 186
Class
- PhpFileLoader
- PhpFileLoader loads service definitions from a PHP file.
Namespace
Symfony\Component\DependencyInjection\LoaderCode
private function configBuilder(string $namespace) : ConfigBuilderInterface {
if (!class_exists(ConfigBuilderGenerator::class)) {
throw new \LogicException('You cannot use the config builder as the Config component is not installed. Try running "composer require symfony/config".');
}
if (null === $this->generator) {
throw new \LogicException('You cannot use the ConfigBuilders without providing a class implementing ConfigBuilderGeneratorInterface.');
}
// If class exists and implements ConfigBuilderInterface
if (class_exists($namespace) && is_subclass_of($namespace, ConfigBuilderInterface::class)) {
return new $namespace();
}
// If it does not start with Symfony\Config\ we don't know how to handle this
if (!str_starts_with($namespace, 'Symfony\\Config\\')) {
throw new InvalidArgumentException(\sprintf('Could not find or generate class "%s".', $namespace));
}
// Try to get the extension alias
$alias = Container::underscore(substr($namespace, 15, -6));
if (str_contains($alias, '\\')) {
throw new InvalidArgumentException('You can only use "root" ConfigBuilders from "Symfony\\Config\\" namespace. Nested classes like "Symfony\\Config\\Framework\\CacheConfig" cannot be used.');
}
if (!$this->container
->hasExtension($alias)) {
$extensions = array_filter(array_map(fn(ExtensionInterface $ext) => $ext->getAlias(), $this->container
->getExtensions()));
throw new InvalidArgumentException(UndefinedExtensionHandler::getErrorMessage($namespace, null, $alias, $extensions));
}
$extension = $this->container
->getExtension($alias);
if (!$extension instanceof ConfigurationExtensionInterface) {
throw new \LogicException(\sprintf('You cannot use the config builder for "%s" because the extension does not implement "%s".', $namespace, ConfigurationExtensionInterface::class));
}
$configuration = $extension->getConfiguration([], $this->container);
$loader = $this->generator
->build($configuration);
return $loader();
}