Skip to content

Commit

Permalink
Merge pull request #8 from barryosull/feature/player_versioning
Browse files Browse the repository at this point in the history
Feature/player versioning
  • Loading branch information
Barry O Sullivan committed Jun 22, 2017
2 parents 224d042 + 7d89447 commit e72b762
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/Player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public function snapshot();
/**
* @return int
*/
public function version();
public static function version();
}
2 changes: 1 addition & 1 deletion src/Contracts/Player/Snapshot/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function last_id();
/**
* @return Integer_
*/
public function updateCount();
public function playerVersion();

/**
* Returns a new Snapshot after resetting it back to its default state.
Expand Down
6 changes: 3 additions & 3 deletions src/Player/AbstractPlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function reset()

public function play($limit = 1000)
{
if ($this->snapshot()->version()->value() != $this->version()) {
throw new \Exception("The snapshot and projector have different versions, playing would cause potential data corruption. This exception only occurs if the players are used incorrectly.");
if ($this->snapshot()->playerVersion()->value() != static::version()) {
throw new \Exception("The snapshot (".$this->snapshot()->version()->value().") and projector (".$this->version().") for '".get_called_class()."' have different versions, playing would cause potential data corruption. This exception only occurs if the players are used incorrectly.");
}

$snapshot_stream = $this->log
Expand Down Expand Up @@ -83,7 +83,7 @@ public function snapshot()
/**
* @return int
*/
public function version()
public static function version()
{
$player_class = get_called_class();

Expand Down
2 changes: 1 addition & 1 deletion src/Player/Collection/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function snapshot()
throw new \Exception("Collection Player Snapshots are not supported.");
}

public function version()
public static function version()
{
throw new \Exception("Collection Player versions are not supported.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/Player/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function hasVersionChanged(ClassName $class_name)

$active_version = new Integer_(1);
if ($snapshot) {
$active_version = $snapshot->version();
$active_version = $snapshot->playerVersion();
}

$player = $this->player_factory->make($class_name);
$player_class = $class_name->value();

return $active_version->value() != $player->version();
return $active_version->value() != $player_class::version();
}
}
2 changes: 1 addition & 1 deletion src/Player/Snapshot/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function make(array $snapshot)
return new Snapshot(
new ClassName($snapshot['class_name']),
new Integer($snapshot['version']),
new Integer($snapshot['update_count']),
new Integer($snapshot['player_version']),
$this->datetime_generator->string($snapshot['occurred_at']),
$this->identifier_generator->string($snapshot['last_id'])
);
Expand Down
22 changes: 11 additions & 11 deletions src/Player/Snapshot/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class Snapshot extends AbstractSnapshot implements \BoundedContext\Contracts\Pla
{
public $last_id;
protected $class_name;
protected $update_count;
protected $player_version;

public function __construct(
ClassName $class_name,
Integer_ $version,
Integer_ $update_count,
Integer_ $player_version,
DateTime $occurred_at,
Identifier $last_id
)
{
parent::__construct($version, $occurred_at);
$this->class_name = $class_name;
$this->update_count = $update_count;
$this->player_version = $player_version;
$this->last_id = $last_id;
}

Expand All @@ -35,13 +35,13 @@ public function last_id()
public function reset(
IdentifierGenerator $identifier_generator,
DateTimeGenerator $datetime_generator,
Integer_ $version
Integer_ $player_version
)
{
return new Snapshot(
$this->class_name,
$version,
$this->update_count->reset(),
$this->version->reset(),
$player_version,
$datetime_generator->now(),
$identifier_generator->null()
);
Expand All @@ -55,7 +55,7 @@ public function skip(
return new Snapshot(
$this->class_name,
$this->version,
$this->update_count,
$this->player_version,
$datetime_generator->now(),
$next_id
);
Expand All @@ -68,8 +68,8 @@ public function take(
{
return new Snapshot(
$this->class_name,
$this->version,
$this->update_count->increment(),
$this->version->increment(),
$this->player_version,
$datetime_generator->now(),
$next_id
);
Expand All @@ -95,8 +95,8 @@ public static function make(
);
}

public function updateCount()
public function playerVersion()
{
return $this->update_count;
return $this->player_version;
}
}

0 comments on commit e72b762

Please sign in to comment.