diff --git a/src/DependencyInjection/ContainerFactory.php b/src/DependencyInjection/ContainerFactory.php index 56ca6b3..8182d8f 100644 --- a/src/DependencyInjection/ContainerFactory.php +++ b/src/DependencyInjection/ContainerFactory.php @@ -32,14 +32,19 @@ public static function create(array|string $settings): ContainerInterface $autoWiresDefinitions = File::require($autoWiresPath, 'Auto wires file does not exist'); // 2. Crete container + $isAutoWiringEnabled = $settingsArray['di']['auto_wires']['enabled']; $containerBuilder = ContainerBuilder::create() ->addSettingsArray($settingsArray) ->addRootPath($settingsArray['rootPath']) ->addRootNamespace($settingsArray['rootNamespace']) - ->useAutoWiring($settingsArray['di']['auto_wires']['enabled']) + ->useAutoWiring($isAutoWiringEnabled) ->useAttributes($settingsArray['di']['attributes']['enabled']) ; + if ($isAutoWiringEnabled) { + $containerBuilder->addDefinitions($autoWiresDefinitions); + } + // 3. Cache if (Environment::from($settingsArray['environment']) === Environment::PRODUCTION) { $containerCachePath = $settingsArray['di']['cache']['container']['path']; @@ -48,7 +53,7 @@ public static function create(array|string $settings): ContainerInterface $containerBuilder ->enableCompilation($containerCachePath) ->addResolverCachePathFile($resolverCachePathFile) - ->addDefinitions($autoWiresDefinitions); + ; } // 4. Add definitions