Skip to content

Commit cc6a53c

Browse files
committed
add generic phpfileloader Symfony 6.2
1 parent 5a4c61f commit cc6a53c

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
--- /dev/null
2+
+++ ../Loader/PhpFileLoader.php
3+
@@ -61,7 +61,15 @@
4+
$callback = $load($path, $this->env);
5+
6+
if (\is_object($callback) && \is_callable($callback)) {
7+
- $this->executeCallback($callback, new ContainerConfigurator($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path);
8+
+ // generic solution
9+
+ $reflectionFunction = new \ReflectionFunction($callback);
10+
+ $containerConfiguratorClass = $reflectionFunction->getParameters()[0]->getType()->getName();
11+
+
12+
+ // generic solution
13+
+ $reflectionFunction = new \ReflectionFunction($callback);
14+
+ $containerConfiguratorClass = $reflectionFunction->getParameters()[0]->getType()->getName();
15+
+
16+
+ $this->executeCallback($callback, new $containerConfiguratorClass($this->container, $this, $this->instanceof, $path, $resource, $this->env), $path);
17+
}
18+
} finally {
19+
$this->instanceof = [];
20+
@@ -112,31 +120,35 @@
21+
}
22+
$type = $reflectionType->getName();
23+
24+
- switch ($type) {
25+
- case ContainerConfigurator::class:
26+
- $arguments[] = $containerConfigurator;
27+
- break;
28+
- case ContainerBuilder::class:
29+
- $arguments[] = $this->container;
30+
- break;
31+
- case FileLoader::class:
32+
- case self::class:
33+
- $arguments[] = $this;
34+
- break;
35+
- case 'string':
36+
- if (null !== $this->env && 'env' === $parameter->getName()) {
37+
- $arguments[] = $this->env;
38+
+ if (is_a($type, ContainerConfigurator::class, true)) {
39+
+ $arguments[] = $containerConfigurator;
40+
+ } else {
41+
+ switch ($type) {
42+
+ case ContainerConfigurator::class:
43+
+ $arguments[] = $containerConfigurator;
44+
break;
45+
- }
46+
+ case ContainerBuilder::class:
47+
+ $arguments[] = $this->container;
48+
+ break;
49+
+ case FileLoader::class:
50+
+ case self::class:
51+
+ $arguments[] = $this;
52+
+ break;
53+
+ case 'string':
54+
+ if (null !== $this->env && 'env' === $parameter->getName()) {
55+
+ $arguments[] = $this->env;
56+
+ break;
57+
+ }
58+
// no break
59+
- default:
60+
- try {
61+
- $configBuilder = $this->configBuilder($type);
62+
- } catch (InvalidArgumentException|\LogicException $e) {
63+
- throw new \InvalidArgumentException(sprintf('Could not resolve argument "%s" for "%s".', $type.' $'.$parameter->getName(), $path), 0, $e);
64+
- }
65+
- $configBuilders[] = $configBuilder;
66+
- $arguments[] = $configBuilder;
67+
+ default:
68+
+ try {
69+
+ $configBuilder = $this->configBuilder($type);
70+
+ } catch (InvalidArgumentException|\LogicException $e) {
71+
+ throw new \InvalidArgumentException(sprintf('Could not resolve argument "%s" for "%s".', $type.' $'.$parameter->getName(), $path), 0, $e);
72+
+ }
73+
+ $configBuilders[] = $configBuilder;
74+
+ $arguments[] = $configBuilder;
75+
+ }
76+
}
77+
}
78+
79+
@@ -160,9 +172,11 @@
80+
throw new \LogicException('You cannot use the config builder as the Config component is not installed. Try running "composer require symfony/config".');
81+
}
82+
83+
+
84+
if (null === $this->generator) {
85+
throw new \LogicException('You cannot use the ConfigBuilders without providing a class implementing ConfigBuilderGeneratorInterface.');
86+
}
87+
+
88+
89+
// If class exists and implements ConfigBuilderInterface
90+
if (class_exists($namespace) && is_subclass_of($namespace, ConfigBuilderInterface::class)) {

0 commit comments

Comments
 (0)