Beispiel #1
0
 public function enrich(CommandInterface $command)
 {
     $metadata = new Metadata($command->getMetadata());
     foreach ($this->items as $metadata_enricher) {
         $metadata = $metadata_enricher->enrich($metadata);
     }
     return $command->withMetadata($metadata);
 }
 protected function checkoutOrCreateAggregateRoot(CommandInterface $command)
 {
     if ($command instanceof AggregateRootCommandInterface) {
         $aggregate_root = $this->getUnitOfWork()->checkout($command->getAggregateRootIdentifier());
     } elseif ($command instanceof CreateAggregateRootCommand) {
         $aggregate_root = $this->getUnitOfWork()->create();
     } else {
         throw new RuntimeError(sprintf('Unable to load an aggregate-root for the given command: %s', $command));
     }
     return $aggregate_root;
 }
Beispiel #3
0
 public function post(CommandInterface $command)
 {
     $command_type = $command->getType();
     if (!$this->subscriptions->hasKey($command_type)) {
         return false;
     }
     $subscription = $this->subscriptions->getItem($command_type);
     $transport = $subscription->getCommandTransport();
     $enriched_command = $this->command_enricher->enrich($command);
     return $transport->send($enriched_command);
 }
Beispiel #4
0
 /**
  * Process the given aggregate-command, hence build the corresponding aggregate-event.
  *
  * @param CommandInterface $command
  * @param array $custom_event_state
  *
  * @return EmbeddedEntityEventInterface
  */
 protected function processEmbeddedEntityCommand(CommandInterface $command, array $custom_event_state = [])
 {
     $event_class = $command->getEventClass();
     $attribute_name = $command->getParentAttributeName();
     $event_state = ['parent_attribute_name' => $attribute_name, 'embedded_entity_type' => $command->getEmbeddedEntityType()];
     if ($command instanceof RemoveEmbeddedEntityCommand) {
         $event_state['embedded_entity_identifier'] = $command->getEmbeddedEntityIdentifier();
     } elseif ($command instanceof AddEmbeddedEntityCommand) {
         $create_data = $command->getValues();
         if (!isset($create_data['identifier'])) {
             $create_data['identifier'] = UuidAttribute::generateVersion4();
         }
         $event_state = array_merge($event_state, ['data' => $create_data, 'position' => $command->getPosition(), 'embedded_entity_identifier' => $create_data['identifier']]);
     } elseif ($command instanceof ModifyEmbeddedEntityCommand) {
         $event_state = array_merge($event_state, ['data' => $command->getValues(), 'position' => $command->getPosition(), 'embedded_entity_identifier' => $command->getEmbeddedEntityIdentifier()]);
     }
     $embedded_entity_events = new EmbeddedEntityEventList();
     foreach ($command->getEmbeddedEntityCommands() as $embedded_command) {
         $embedded_entity_events->push($this->processEmbeddedEntityCommand($embedded_command));
     }
     $event_state['embedded_entity_events'] = $embedded_entity_events;
     return new $event_class($event_state);
 }
 public function send(CommandInterface $command)
 {
     $this->job_service->dispatch(new ExecuteCommandJob($this->command_bus, ['command' => $command]), new Settings(['routing_key' => $this->queue_name ?: $command->getType(), 'exchange' => $this->exchange]));
 }