repo->ofKey($cmd->key); // Update the value of the option $option->setValue($cmd->value); // Create the event to be dispatched $event = new OptionUpdatedEvent($option); } catch (OptionNotFoundException) { // If the option does not exist, create a new one $option = new OptionEntity( $cmd->key, $cmd->value, ); // Add the option to the repository $this->repo->add($option); // Create the event to be dispatched $event = new OptionCreatedEvent($option); } // Dispatch the event $this->dispatcher->dispatch($event); return $option; } }