2222
2323use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
2424use Symfony \Component \Config \Definition \ConfigurationInterface ;
25- use Symfony \Component \DependencyInjection \ ContainerBuilder ;
25+ use Symfony \Component \HttpKernel \ Bundle \ BundleInterface ;
2626
27- class Configuration implements ConfigurationInterface
27+ final class Configuration implements ConfigurationInterface
2828{
29- private ContainerBuilder $ container ;
30-
31- public function __construct (ContainerBuilder $ container )
32- {
33- $ this ->container = $ container ;
29+ public function __construct (
30+ /** @var array<string, class-string<BundleInterface>> */
31+ private array $ bundles ,
32+ ) {
3433 }
3534
35+ #[\Override()]
3636 public function getConfigTreeBuilder (): TreeBuilder
3737 {
38- $ c = $ this ->container ;
39-
40- $ tb = new TreeBuilder ('jms_translation ' );
41- // Keep compatibility with symfony/config < 4.2
42- if (!method_exists ($ tb , 'getRootNode ' )) {
43- $ rootNode = $ tb ->root ('jms_translation ' );
44- } else {
45- $ rootNode = $ tb ->getRootNode ();
46- }
38+ $ treeBuilder = new TreeBuilder ('jms_translation ' );
39+ $ rootNode = $ treeBuilder ->getRootNode ();
4740
4841 $ rootNode
4942 ->fixXmlConfig ('config ' )
@@ -77,7 +70,7 @@ public function getConfigTreeBuilder(): TreeBuilder
7770 ->requiresAtLeastOneElement ()
7871 ->prototype ('scalar ' )
7972 ->validate ()
80- ->always (static function ($ v ) use ( $ c ) {
73+ ->always (function ($ v ): string {
8174 $ v = str_replace (DIRECTORY_SEPARATOR , '/ ' , $ v );
8275
8376 if ('@ ' === $ v [0 ]) {
@@ -87,12 +80,11 @@ public function getConfigTreeBuilder(): TreeBuilder
8780 $ bundleName = substr ($ v , 1 , $ pos - 1 );
8881 }
8982
90- $ bundles = $ c ->getParameter ('kernel.bundles ' );
91- if (!isset ($ bundles [$ bundleName ])) {
92- throw new \Exception (sprintf ('The bundle "%s" does not exist. Available bundles: %s ' , $ bundleName , implode (', ' , array_keys ($ bundles ))));
83+ if (null === $ bundleClass = ($ this ->bundles [$ bundleName ] ?? null )) {
84+ throw new \Exception (sprintf ('The bundle "%s" does not exist. Available bundles: %s ' , $ bundleName , implode (', ' , array_keys ($ this ->bundles ))));
9385 }
9486
95- $ ref = new \ReflectionClass ($ bundles [ $ bundleName ] );
87+ $ ref = new \ReflectionClass ($ bundleClass );
9688 $ v = false === $ pos ? dirname ($ ref ->getFileName ()) : dirname ($ ref ->getFileName ()) . substr ($ v , $ pos );
9789 }
9890
@@ -130,6 +122,6 @@ public function getConfigTreeBuilder(): TreeBuilder
130122 ->end ()
131123 ->end ();
132124
133- return $ tb ;
125+ return $ treeBuilder ;
134126 }
135127}
0 commit comments