Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down