final class CommandSimulator (View source)

internal  
 

The CommandSimulator is used during the publishing process, for partial publishing and workspace rebasing.

For this case, we want to apply commands including their constraint checks step by step, to see whether this set of commands applies cleanly without errors, and which events would be created by them, but we do NOT want to commit the updated projections or events.

Internally, we do the following:

  • Create a database transaction in the GraphProjection which we will roll back lateron (to dry-run projection updates) (via {\Neos\ContentRepository\Core\CommandHandler\CommandSimulator::run()}). - Create an InMemoryEventStore which buffers created events by command handlers.
  • execute all commands via {\Neos\ContentRepository\Core\CommandHandler\CommandSimulator::handle()} - -> this will do all constraint checks based on the projection in the open transaction (so it sees previously modified projection state which is not committed)
  • -> it will run the command handlers, buffer all emitted events in the InMemoryEventStore -> note to avoid full recursion the workspace command handler is not included in the bus
  • -> update the GraphProjection, but WITHOUT committing the transaction {[\Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjectionInterface::inSimulation()}

This](../../../../Neos/ContentRepository/Core/Projection/ContentGraph/ContentGraphProjectionInterface.html) is quite performant because we do not need to fork a new content stream.

Methods

__construct(ContentGraphProjectionInterface $contentRepositoryProjection, EventNormalizer $eventNormalizer, CommandBus $commandBus, WorkspaceName $workspaceNameToSimulateIn)

No description

mixed
run(callable $fn)

Start the simulation for the passed function which receives as argument the {handle} function.

SequenceNumber
currentSequenceNumber()

No description

EventStreamInterface
eventStream()

No description

bool
hasConflicts()

No description

Details

__construct(ContentGraphProjectionInterface $contentRepositoryProjection, EventNormalizer $eventNormalizer, CommandBus $commandBus, WorkspaceName $workspaceNameToSimulateIn)

No description

Parameters

ContentGraphProjectionInterface $contentRepositoryProjection
EventNormalizer $eventNormalizer
CommandBus $commandBus
WorkspaceName $workspaceNameToSimulateIn

mixed run(callable $fn)

Start the simulation for the passed function which receives as argument the {handle} function.

Parameters

callable $fn

Return Value

mixed

the return value of $fn

SequenceNumber currentSequenceNumber()

No description

Return Value

SequenceNumber

EventStreamInterface eventStream()

No description

Return Value

EventStreamInterface

bool hasConflicts()

No description

Return Value

bool

ConflictingEvents getConflictingEvents()

No description

Return Value

ConflictingEvents