コード例 #1
0
 private function createProxy(AggregateContainer $aggregateContainer)
 {
     $serializedMetadata = $aggregateContainer->serializedMetadata();
     $aggregateClassName = $this->serializer->getAggregateClass($serializedMetadata);
     return $this->proxyFactory->createProxy($aggregateClassName, function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use($aggregateContainer) {
         $serializationResult = new SerializationResult($aggregateContainer->serializedAggregate(), $aggregateContainer->serializedMetadata());
         $wrappedObject = $this->serializer->deserialize($serializationResult, $this);
         $initializer = null;
         // turning off further lazy initialization
         $aggregateContainer->setAggregate($wrappedObject);
     });
 }
コード例 #2
0
 public function add(AggregateContainer $container)
 {
     $aggregateRootId = $container->aggregateRootId();
     $aggregate = $container->aggregate();
     if (!isset($this->containers[$aggregateRootId])) {
         $objectHash = spl_object_hash($aggregate);
         if (isset($this->aggregateRootIds[$objectHash])) {
             throw new AggregatePersistedWithMultipleIdsException();
         }
         $this->containers[$aggregateRootId] = $container;
         $this->aggregateRootIds[$objectHash] = $aggregateRootId;
         $container->onSetAggregate(function ($newAggregateInstance) use($aggregateRootId) {
             $newObjectHash = spl_object_hash($newAggregateInstance);
             $this->aggregateRootIds[$newObjectHash] = $aggregateRootId;
         });
     } elseif ($aggregate !== $this->containers[$aggregateRootId]->aggregate()) {
         throw new AggregateIdCollisionException();
     }
 }