Prooph\EventStore\Aggregate\ConfigurableAggregateTranslator::extractAggregateVersion PHP Метод

extractAggregateVersion() публичный Метод

public extractAggregateVersion ( object $eventSourcedAggregateRoot ) : integer
$eventSourcedAggregateRoot object
Результат integer
    public function extractAggregateVersion($eventSourcedAggregateRoot)
    {
        if (!method_exists($eventSourcedAggregateRoot, $this->versionMethodName)) {
            throw new AggregateTranslationFailedException(sprintf('Required method %s does not exist for aggregate %s', $this->versionMethodName, get_class($eventSourcedAggregateRoot)));
        }
        return (int) $eventSourcedAggregateRoot->{$this->versionMethodName}();
    }

Usage Example

 /**
  * @test
  * @expectedException \Prooph\EventStore\Aggregate\Exception\AggregateTranslationFailedException
  */
 public function it_throws_exception_if_version_method_does_not_exist()
 {
     $ar = $this->prophesize(CustomAggregateRootContract::class);
     $translator = new ConfigurableAggregateTranslator('unknownMethodName');
     $translator->extractAggregateVersion($ar->reveal());
 }