コード例 #1
0
 public function let(UnitOfWork $unitOfWork, UnitOfWorkEventRegistrationCallbackFactory $eventRegistrationCallbackFactory, AggregateRoot $aggregateRoot1, AggregateRoot $aggregateRoot2, EventBus $eventBus, SaveAggregateCallback $saveAggregateCallback, EventRegistrationCallback $eventRegistrationCallback)
 {
     $eventRegistrationCallbackFactory->create(Argument::any(), Argument::any())->willReturn($eventRegistrationCallback);
     $this->beConstructedWith($unitOfWork, $eventRegistrationCallbackFactory);
     $this->add($aggregateRoot1, $eventBus, $saveAggregateCallback);
     $this->add($aggregateRoot2, $eventBus, $saveAggregateCallback);
 }
コード例 #2
0
 /**
  * @param AggregateRoot         $aggregateRoot
  * @param EventBus              $eventBus
  * @param SaveAggregateCallback $saveAggregateCallback
  *
  * @return AggregateRoot
  */
 public function add(AggregateRoot $aggregateRoot, EventBus $eventBus, SaveAggregateCallback $saveAggregateCallback)
 {
     $previouslyRegisteredAggregateRoot = $this->findSimilarAggregateRoot($aggregateRoot);
     if (null !== $previouslyRegisteredAggregateRoot) {
         return $previouslyRegisteredAggregateRoot;
     }
     $aggregateRootHash = $this->getAggregateRootHash($aggregateRoot);
     $this->aggregateRoots[$aggregateRootHash] = $aggregateRoot;
     $this->aggregateRootSaveCallbacks[$aggregateRootHash] = $saveAggregateCallback;
     $eventRegistrationCallback = $this->eventRegistrationCallbackFactory->create($this->unitOfWork, $eventBus);
     $aggregateRoot->addEventRegistrationCallback($eventRegistrationCallback);
     return $aggregateRoot;
 }