diff --git a/config/dependencies.php b/config/dependencies.php index ec38e514f..3aea3da68 100644 --- a/config/dependencies.php +++ b/config/dependencies.php @@ -25,6 +25,7 @@ */ // Parsedown: injects Config and Builder \Cecil\Converter\Parsedown::class => autowire() + ->constructorParameter('builder', get(\Cecil\Builder::class)) ->constructorParameter('config', get(\Cecil\Config::class)) ->constructorParameter('options', null), // Converter: automatically injects Parsedown diff --git a/src/Builder.php b/src/Builder.php index 9d8ec570a..f9e651cfc 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -19,6 +19,7 @@ use Cecil\Generator\GeneratorManager; use Cecil\Logger\PrintLogger; use DI\Container; +use DI\NotFoundException; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Finder\Finder; @@ -280,11 +281,18 @@ public function build(array $options): self $steps = []; // init... foreach (self::STEPS as $step) { - // Use DI container to create steps + // Use DI container to create steps with dependency injection. + // All steps defined in the DI container configuration should be resolved from the container. + // Falls back to direct instantiation only if a step is not registered in the container. try { $stepObject = $this->container->get($step); - } catch (\Exception $e) { + } catch (NotFoundException $e) { // Fallback for steps not declared in the container + // This should rarely happen as all steps in STEPS constant are defined in the DI container configuration + $this->getLogger()->warning(sprintf( + 'Step %s not found in DI container, using direct instantiation as fallback', + $step + )); $stepObject = new $step($this); } $stepObject->init($this->options);