--- /dev/null +++ ../Loader/PhpFileLoader.php @@ -64,7 +64,11 @@ $callback = $load($path, $this->env); if (\is_object($callback) && \is_callable($callback)) { - $this->executeCallback($callback, new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path); + // generic solution + $reflectionFunction = new \ReflectionFunction($callback); + $containerConfiguratorClass = $reflectionFunction->getParameters()[0]->getType()->getName(); + + $this->executeCallback($callback, new $containerConfiguratorClass($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path); } } finally { $this->instanceof = []; @@ -121,25 +125,26 @@ } $type = $reflectionType->getName(); - switch ($type) { - case ContainerConfigurator::class: - $arguments[] = $containerConfigurator; - break; - case ContainerBuilder::class: - $arguments[] = $this->container; - break; - case FileLoader::class: - case self::class: - $arguments[] = $this; - break; - default: - try { - $configBuilder = $this->configBuilder($type); - } catch (InvalidArgumentException|\LogicException $e) { - throw new \InvalidArgumentException(sprintf('Could not resolve argument "%s" for "%s".', $type.' $'.$parameter->getName(), $path), 0, $e); - } - $configBuilders[] = $configBuilder; - $arguments[] = $configBuilder; + if (is_a($type, ContainerConfigurator::class, true)) { + $arguments[] = $containerConfigurator; + } else { + switch ($type) { + case ContainerBuilder::class: + $arguments[] = $this->container; + break; + case FileLoader::class: + case self::class: + $arguments[] = $this; + break; + default: + try { + $configBuilder = $this->configBuilder($type); + } catch (InvalidArgumentException|\LogicException $e) { + throw new \InvalidArgumentException(sprintf('Could not resolve argument "%s" for "%s".', $type.' $'.$parameter->getName(), $path), 0, $e); + } + $configBuilders[] = $configBuilder; + $arguments[] = $configBuilder; + } } } @@ -163,9 +168,11 @@ 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)) {