Skip to content

Commit

Permalink
TASK: Declare $handlers of CommandBus private
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 28, 2024
1 parent 08a0d67 commit 3761fc2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
/**
* @var CommandHandlerInterface[]
*/
public array $handlers;
private array $handlers;

public function __construct(
// todo pass $commandHandlingDependencies in each command handler instead of into the commandBus
private CommandHandlingDependencies $commandHandlingDependencies,
CommandHandlerInterface ...$handlers
) {
Expand All @@ -40,4 +41,13 @@ public function handle(CommandInterface $command): EventsToPublish|\Generator
}
throw new \RuntimeException(sprintf('No handler found for Command "%s"', get_debug_type($command)), 1649582778);
}

public function withAdditionalHandlers(CommandHandlerInterface ...$handlers): self
{
return new self(
$this->commandHandlingDependencies,
...$this->handlers,
...$handlers,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public function getOrBuild(): ContentRepository
$commandHandlingDependencies = new CommandHandlingDependencies($contentGraphReadModel);

// we dont need full recursion in rebase - e.g apply workspace commands - and thus we can use this set for simulation
// todo pass $commandHandlingDependencies in each command handler instead of into the commandBus
$commandBusForRebaseAbleCommands = new CommandBus(
$commandBusForRebaseableCommands = new CommandBus(
$commandHandlingDependencies,
new NodeAggregateCommandHandler(
$this->projectionFactoryDependencies->nodeTypeManager,
Expand All @@ -118,18 +117,16 @@ public function getOrBuild(): ContentRepository
$commandSimulatorFactory = new CommandSimulatorFactory(
$this->projectionsAndCatchUpHooks->contentGraphProjection,
$this->projectionFactoryDependencies->eventNormalizer,
$commandBusForRebaseAbleCommands
$commandBusForRebaseableCommands
);

$publicCommandBus = new CommandBus(
$commandHandlingDependencies,
$publicCommandBus = $commandBusForRebaseableCommands->withAdditionalHandlers(
new ContentStreamCommandHandler(),
new WorkspaceCommandHandler(
$commandSimulatorFactory,
$this->projectionFactoryDependencies->eventStore,
$this->projectionFactoryDependencies->eventNormalizer,
),
...$commandBusForRebaseAbleCommands->handlers
)
);

return $this->contentRepository = new ContentRepository(
Expand Down

0 comments on commit 3761fc2

Please sign in to comment.