Skip to content
Browse files

Backport to 5.2

  • Loading branch information...
1 parent 57dd3cd commit 216e5b37d68c419ad0945d07713fc999cc3791d9 @matzko committed Jul 31, 2011
View
2 README.md
@@ -1,4 +1,4 @@
Tracks
======
-A CQRS framework for PHP 5.3
+A CQRS framework for PHP 5.2
View
4 examples/example1/Employee.php
@@ -24,7 +24,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Employee extends \Tracks\Model\Entity
+class Employee extends Tracks_Model_Entity
{
public function __construct($guid, $name)
{
@@ -52,7 +52,7 @@ private function registerEvents()
public $position;
}
-class EventEmployeeChangeTitle extends \Tracks\Event\Base
+class EventEmployeeChangeTitle extends Tracks_Event_Base
{
public function __construct($guid, $title)
{
View
16 examples/example1/Employer.php
@@ -24,30 +24,30 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Employer extends \Tracks\Model\AggregateRoot
+class Employer extends Tracks_Model_AggregateRoot
{
public function __construct()
{
- $this->employees = new \Tracks\Model\EntityList;
+ $this->employees = new Tracks_Model_EntityList;
$this->registerEvents();
}
public function create($name)
{
- $guid = \Tracks\Model\Guid::create();
+ $guid = Tracks_Model_Guid::create();
$this->applyEvent(new EventEmployerCreated($guid, $name));
return $guid;
}
public function addNewEmployee($name, $title)
{
- $employeeGuid = \Tracks\Model\Guid::create();
+ $employeeGuid = Tracks_Model_Guid::create();
$this->applyEvent(new EventEmployeeAdded($this->getGuid(), $employeeGuid, $name));
$this->employees->find($employeeGuid)->changeTitle($title);
return $employeeGuid;
}
- public function changeEmployeeTitle(\Tracks\Model\Guid $employeeGuid, $title)
+ public function changeEmployeeTitle(Tracks_Model_Guid $employeeGuid, $title)
{
if ($employee = $this->employees->find($employeeGuid)) {
$employee->changeTitle($title);
@@ -75,7 +75,7 @@ private function registerEvents()
public $employees;
}
-class EventEmployerCreated extends \Tracks\Event\Base
+class EventEmployerCreated extends Tracks_Event_Base
{
public function __construct($guid, $name)
{
@@ -86,9 +86,9 @@ public function __construct($guid, $name)
public $name;
}
-class EventEmployeeAdded extends \Tracks\Event\Base
+class EventEmployeeAdded extends Tracks_Event_Base
{
- public function __construct(\Tracks\Model\Guid $guid, $employeeGuid, $name)
+ public function __construct(Tracks_Model_Guid $guid, $employeeGuid, $name)
{
parent::__construct($guid);
$this->employeeGuid = $employeeGuid;
View
6 examples/example1/Welcomer.php
@@ -24,11 +24,11 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Welcomer implements \Tracks\EventHandler\IEventHandler
+class Welcomer implements Tracks_EventHandler_IEventHandler
{
- public function execute(\Tracks\Event\Base $event)
+ public function execute(Tracks_Event_Base $event)
{
echo 'Welcome aboard, '.$event->name.'!'.PHP_EOL;
}
-}
+}
View
8 examples/example1/example1.php
@@ -19,13 +19,13 @@
require_once 'Position.php';
require_once 'Welcomer.php';
-$router = new \Tracks\EventHandler\DirectRouter;
+$router = new Tracks_EventHandler_DirectRouter;
$router->addHandler('EventEmployeeAdded', 'Welcomer');
-$repository = new \Tracks\EventStore\Repository(
- new \Tracks\EventStore\EventStorage\Memory,
+$repository = new Tracks_EventStore_Repository(
+ new Tracks_EventStore_EventStorage_Memory,
$router,
- new \Tracks\EventStore\SnapshotStorage\Memory
+ new Tracks_EventStore_SnapshotStorage_Memory
);
$employer = new Employer;
View
13 library/Tracks/Event/Base.php
@@ -12,9 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Event;
-use Tracks\Model\Guid;
-
/**
* Domain Event base class
*
@@ -25,31 +22,31 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-abstract class Base
+abstract class Tracks_Event_Base
{
/**
* Constructor
*
- * @param Guid $guid Event GUID
+ * @param Tracks_Model_Guid $guid Event GUID
*
* @return null
*/
- public function __construct(Guid $guid)
+ public function __construct(Tracks_Model_Guid $guid)
{
$this->guid = $guid;
}
/**
* Get the entity guid this event is associated with
*
- * @return Tracks\Model\Guid
+ * @return Tracks_Model_Guid
*/
public function getGuid()
{
return $this->guid;
}
- /** @var \Tracks\Model\Guid */
+ /** @var Tracks_Model_Guid */
public $guid;
}
View
12 library/Tracks/EventHandler/DirectRouter.php
@@ -12,8 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventHandler;
-
/**
* Routes directly to an event handler object in the same process
*
@@ -26,17 +24,17 @@
*/
-class DirectRouter implements IEventRouter
+class Tracks_EventHandler_DirectRouter implements ITracks_EventHandler_EventRouter
{
/**
* Route an event
*
- * @param Tracks\Event\Base $event An Event
+ * @param Tracks_Event_Base $event An Event
*
* @return null
*/
- public function route(\Tracks\Event\Base $event)
+ public function route(Tracks_Event_Base $event)
{
if (isset($this->_handlers[get_class($event)])) {
foreach ($this->_handlers[get_class($event)] as $handler) {
@@ -57,7 +55,7 @@ public function route(\Tracks\Event\Base $event)
* required parameters on it's constructor.
*
* @param string $eventClass The Event classname
- * @param IEventHandler|string $handler An EventHandler
+ * @param Tracks_EventHandler_IEventHandler|string $handler An EventHandler
*
* @return null
*/
@@ -66,7 +64,7 @@ public function addHandler($eventClass, $handler)
assert('is_string($eventClass)');
assert('class_exists($eventClass)');
if (is_object($handler)
- && !($handler instanceof \Tracks\EventHandler\IEventHandler)
+ && !($handler instanceof Tracks_EventHandler_IEventHandler)
) {
throw new LogicException('Event handlers must implement IEventHandler');
}
View
8 library/Tracks/EventHandler/IEventHandler.php
@@ -12,8 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventHandler;
-
/**
* Interface for event handlers
*
@@ -24,14 +22,14 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-interface IEventHandler
+interface Tracks_EventHandler_IEventHandler
{
/**
* Execute an event
*
- * @param Tracks\Event\Base $event An Event
+ * @param Tracks_Event_Base $event An Event
*
* @return null
*/
- public function execute(\Tracks\Event\Base $event);
+ public function execute(Tracks_Event_Base $event);
}
View
8 library/Tracks/EventHandler/IEventRouter.php
@@ -12,8 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventHandler;
-
/**
* Interface for event routers
*
@@ -24,16 +22,16 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-interface IEventRouter
+interface Tracks_EventHandler_IEventRouter
{
/**
* Route an event
*
- * @param Tracks\Event\Base $event An Event
+ * @param Tracks_Event_Base $event An Event
*
* @return null
*/
- public function route(\Tracks\Event\Base $event);
+ public function route(Tracks_Event_Base $event);
/**
* Add an event handler to the routing table
View
30 library/Tracks/EventStore/EventStorage/Memory.php
@@ -13,10 +13,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore\EventStorage;
-use \Tracks\EventStore\IEventStore;
-use \Tracks\Model\Guid, \Tracks\Model\Entity;
-
/**
* In-Memory event store implementation
*
@@ -28,30 +24,30 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Memory implements IEventStore
+class Tracks_EventStore_EventStorage_Memory implements Tracks_EventStore_IEventStore
{
/**
* Get all the events associated with an entity by guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return array
*/
- public function getAllEvents(Guid $guid)
+ public function getAllEvents(Tracks_Model_Guid $guid)
{
return $this->_events[(string) $guid];
}
/**
* Get all events associated with an entity starting from a particular version
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
* @param int $version That Entity's version number
*
* @return array
*/
- public function getEventsFromVersion(Guid $guid, $version)
+ public function getEventsFromVersion(Tracks_Model_Guid $guid, $version)
{
assert('is_int($version)');
return array_slice($this->_events[(string) $guid], $version);
@@ -60,11 +56,11 @@ public function getEventsFromVersion(Guid $guid, $version)
/**
* Save an entity and it's events
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- public function save(Entity $entity)
+ public function save(Tracks_Model_Entity $entity)
{
foreach ($entity->getAllEntities() as $provider) {
$this->_createEntity($provider);
@@ -79,23 +75,23 @@ public function save(Entity $entity)
/**
* Get the object type associated with a guid
*
- * @param Guid $guid Any GUID
+ * @param Tracks_Model_Guid $guid Any GUID
*
* @return string
*/
- public function getType(Guid $guid)
+ public function getType(Tracks_Model_Guid $guid)
{
return $this->entities[(string) $guid]['type'];
}
/**
* Create a new entity entry if it doesn't already exist
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- private function _createEntity(Entity $entity)
+ private function _createEntity(Tracks_Model_Entity $entity)
{
if (!isset($this->_entities[(string) $entity->getGuid()])) {
$this->_entities[(string) $entity->getGuid()] = array(
@@ -112,11 +108,11 @@ private function _createEntity(Entity $entity)
/**
* Increment the version of an entity
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return null
*/
- private function _incVersion(Guid $guid)
+ private function _incVersion(Tracks_Model_Guid $guid)
{
isset($this->entities[(string) $guid])
? $this->entities[(string) $guid]['version']++
View
34 library/Tracks/EventStore/EventStorage/ZendDb.php
@@ -13,10 +13,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore\EventStorage;
-use Tracks\EventStore\IEventStore;
-use Tracks\Model\Guid, Tracks\Model\Entity;
-
/**
* Zend_Db based implementation of the event store.
*
@@ -31,7 +27,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class ZendDb implements IEventStore
+class Tracks_EventStore_EventStorage_ZendDb implements Tracks_EventStore_IEventStore
{
/**
@@ -49,11 +45,11 @@ public function __construct(\Zend_Db_Adapter_Abstract $dbh)
/**
* Get all events associated with a guid
*
- * @param Guid $guid Any GUID
+ * @param Tracks_Model_Guid $guid Any GUID
*
* @return array
*/
- public function getAllEvents(Guid $guid)
+ public function getAllEvents(Tracks_Model_Guid $guid)
{
$select = $this->_dbh->select()
->from('event', array('*'))
@@ -73,11 +69,11 @@ public function getAllEvents(Guid $guid)
/**
* Save an entity to the data store
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- public function save(Entity $entity)
+ public function save(Tracks_Model_Entity $entity)
{
foreach ($entity->getAllEntities() as $child) {
$this->_createEntity($child);
@@ -92,12 +88,12 @@ public function save(Entity $entity)
/**
* Get events associated with a guid, starting with a specific version number
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
* @param int $version That Entity's version number
*
* @return array
*/
- public function getEventsFromVersion(Guid $guid, $version)
+ public function getEventsFromVersion(Tracks_Model_Guid $guid, $version)
{
assert('is_int($version)');
$select = $this->_dbh->select()
@@ -119,11 +115,11 @@ public function getEventsFromVersion(Guid $guid, $version)
/**
* Get the object type of an entity
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return string
*/
- public function getType(Guid $guid)
+ public function getType(Tracks_Model_Guid $guid)
{
if (is_null($row = $this->_getEntityByGuid($guid))) {
return null;
@@ -150,11 +146,11 @@ private function _createEvent(\Tracks\Event\Base $event)
/**
* Create an entity record
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- private function _createEntity(Entity $entity)
+ private function _createEntity(Tracks_Model_Entity $entity)
{
if (is_null($this->_getEntityByGuid($entity->getGuid()))) {
$this->_dbh->insert(
@@ -170,11 +166,11 @@ private function _createEntity(Entity $entity)
/**
* Get the entity record by guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return array
*/
- private function _getEntityByGuid(Guid $guid)
+ private function _getEntityByGuid(Tracks_Model_Guid $guid)
{
$select = $this->_dbh->select()
->from('event', array('*'))
@@ -190,11 +186,11 @@ private function _getEntityByGuid(Guid $guid)
/**
* Increment the version of an entity in the data store
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return null
*/
- private function _incVersion(Guid $guid)
+ private function _incVersion(Tracks_Model_Guid $guid)
{
$this->_dbh->update(
'entity',
View
21 library/Tracks/EventStore/IEventStore.php
@@ -12,9 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore;
-use \Tracks\Model\Guid, \Tracks\Model\Entity;
-
/**
* Interface for event stores
*
@@ -25,43 +22,43 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-interface IEventStore
+interface Tracks_EventStore_IEventStore
{
/**
* Get all the events associated with an entity by guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return array
*/
- public function getAllEvents(Guid $guid);
+ public function getAllEvents(Tracks_Model_Guid $guid);
/**
* Get all events associated with an entity starting from a particular version
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
* @param int $version That Entity's version number
*
* @return array
*/
- public function getEventsFromVersion(Guid $guid, $version);
+ public function getEventsFromVersion(Tracks_Model_Guid $guid, $version);
/**
* Get the object type associated with a guid
*
- * @param Guid $guid Any GUID
+ * @param Tracks_Model_Guid $guid Any GUID
*
* @return string
*/
- public function getType(Guid $guid);
+ public function getType(Tracks_Model_Guid $guid);
/**
* Save an entity and it's events
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- public function save(Entity $entity);
+ public function save(Tracks_Model_Entity $entity);
}
View
15 library/Tracks/EventStore/ISnapshotStore.php
@@ -12,9 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore;
-use Tracks\Model\Guid, Tracks\Model\Entity;
-
/**
* Interface for snapshot stores
*
@@ -25,23 +22,23 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-interface ISnapshotStore
+interface Tracks_EventStore_ISnapshotStore
{
/**
* Load an Entity
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return Entity|null
+ * @return Tracks_Model_Entity|null
*/
- public function load(Guid $guid);
+ public function load(Tracks_Model_Guid $guid);
/**
* Save an Entity
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- public function save(Entity $entity);
+ public function save(Tracks_Model_Entity $entity);
}
View
68 library/Tracks/EventStore/Repository.php
@@ -12,10 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore;
-use Tracks\EventHandler\IEventRouter;
-use Tracks\Model\AggregateRoot, Tracks\Model\Entity, Tracks\Model\Guid;
-
/**
* Repository to load and save domain event-based entities
*
@@ -26,7 +22,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Repository
+class Tracks_EventStore_Repository
{
const SNAPSHOT_FREQUENCY = 100;
@@ -35,14 +31,14 @@ class Repository
* Constructor
*
* @param IEventStore $eventStore The Event Store
- * @param IEventRouter $router The Event Router
+ * @param Tracks_EventHandler_IEventRouter $router The Event Router
* @param ISnapshotStore $snapshotStore The Snapshot Store
*
* @return null
*/
public function __construct(
IEventStore $eventStore,
- IEventRouter $router,
+ Tracks_EventHandler_IEventRouter $router,
ISnapshotStore $snapshotStore
) {
$this->eventStore = $eventStore;
@@ -54,11 +50,11 @@ public function __construct(
/**
* Load an entity by a guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return \Tracks\Model\AggregateRoot
+ * @return Tracks_Model_AggregateRoot
*/
- public function load(Guid $guid)
+ public function load(Tracks_Model_Guid $guid)
{
if (is_null($aggregateRoot = $this->_loadEntity($guid))) {
return null;
@@ -91,11 +87,11 @@ public function setSnapshotFrequency($numEvents = self::SNAPSHOT_FREQUENCY)
/**
* Save an aggregate root, and call event handlers for all new events
*
- * @param AggregateRoot $aggregateRoot An Aggregate Root
+ * @param Tracks_Model_AggregateRoot $aggregateRoot An Aggregate Root
*
* @return null
*/
- public function save(AggregateRoot $aggregateRoot)
+ public function save(Tracks_Model_AggregateRoot $aggregateRoot)
{
if (count($aggregateRoot->getAllAppliedEvents()) == 0) {
return;
@@ -110,23 +106,23 @@ public function save(AggregateRoot $aggregateRoot)
/**
* Store an entity in the identity map
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- private function _storeInIdentityMap(Entity $entity)
+ private function _storeInIdentityMap(Tracks_Model_Entity $entity)
{
$this->_identityMap[(string) $entity->getGuid()] = $entity;
}
/**
* Attempt to load an entity from the identity map
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return \Tracks\Model\Entity
+ * @return Tracks_Model_Entity
*/
- private function _loadFromIdentityMap(Guid $guid)
+ private function _loadFromIdentityMap(Tracks_Model_Guid $guid)
{
return isset($this->_identityMap[(string) $guid])
? $this->_identityMap[(string) $guid]
@@ -136,12 +132,12 @@ private function _loadFromIdentityMap(Guid $guid)
/**
* Load an entity from it's event history
*
- * @param Guid $guid An Entity's GUID
- * @param Entity $entity That Entity
+ * @param Tracks_Model_Guid $guid An Entity's GUID
+ * @param Tracks_Model_Entity $entity That Entity
*
- * @return \Tracks\Model\Entity
+ * @return Tracks_Model_Entity
*/
- private function _loadFromHistory(Guid $guid, Entity $entity = null)
+ private function _loadFromHistory(Tracks_Model_Guid $guid, Tracks_Model_Entity $entity = null)
{
$events = $this->eventStore->getAllEvents($guid);
@@ -161,12 +157,12 @@ private function _loadFromHistory(Guid $guid, Entity $entity = null)
/**
* Load an entity into memory
*
- * @param Guid $guid An Entity's GUID
- * @param Entity $entity That Entity
+ * @param Tracks_Model_Guid $guid An Entity's GUID
+ * @param Tracks_Model_Entity $entity That Entity
*
- * @return Tracks\Model\Entity
+ * @return Tracks_Model_Entity
*/
- private function _loadEntity(Guid $guid, Entity $entity = null)
+ private function _loadEntity(Tracks_Model_Guid $guid, Tracks_Model_Entity $entity = null)
{
$loadedEntity = $this->_loadFromIdentityMap($guid);
@@ -190,11 +186,11 @@ private function _loadEntity(Guid $guid, Entity $entity = null)
/**
* Route all new events on an aggregate to their appropriate handlers
*
- * @param AggregateRoot $aggregateRoot An Aggregate Root
+ * @param Tracks_Model_AggregateRoot $aggregateRoot An Aggregate Root
*
* @return null
*/
- private function _routeEvents(AggregateRoot $aggregateRoot)
+ private function _routeEvents(Tracks_Model_AggregateRoot $aggregateRoot)
{
foreach ($aggregateRoot->getAllAppliedEvents() as $event) {
$this->router->route($event);
@@ -204,11 +200,11 @@ private function _routeEvents(AggregateRoot $aggregateRoot)
/**
* Attempt to load an entity from a snapshot
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return \Tracks\Model\Entity
+ * @return Tracks_Model_Entity
*/
- private function _loadFromSnapshot(Guid $guid)
+ private function _loadFromSnapshot(Tracks_Model_Guid $guid)
{
if (is_null($entity = $this->snapshotStore->load($guid))) {
return null;
@@ -229,11 +225,11 @@ private function _loadFromSnapshot(Guid $guid)
*
* This should be called after an entity's events have been saved.
*
- * @param AggregateRoot $aggregateRoot An Aggregate Root
+ * @param Tracks_Model_AggregateRoot $aggregateRoot An Aggregate Root
*
* @return null
*/
- private function _updateVersionsAndClearEvents(AggregateRoot $aggregateRoot)
+ private function _updateVersionsAndClearEvents(Tracks_Model_AggregateRoot $aggregateRoot)
{
foreach ($aggregateRoot->getAllEntities() as $entity) {
$entity->incVersion(count($entity->getAppliedEvents()));
@@ -244,11 +240,11 @@ private function _updateVersionsAndClearEvents(AggregateRoot $aggregateRoot)
/**
* Attempt to save a snapshot for all entites in an aggregate root
*
- * @param AggregateRoot $aggregateRoot An Aggregate Root
+ * @param Tracks_Model_AggregateRoot $aggregateRoot An Aggregate Root
*
* @return null
*/
- private function _saveSnapshots(AggregateRoot $aggregateRoot)
+ private function _saveSnapshots(Tracks_Model_AggregateRoot $aggregateRoot)
{
foreach ($aggregateRoot->getAllEntities() as $entity) {
$this->_saveSnapshot($entity);
@@ -258,11 +254,11 @@ private function _saveSnapshots(AggregateRoot $aggregateRoot)
/**
* Try to save a snapshot of an entity if frequency determines it is time
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- private function _saveSnapshot(Entity $entity)
+ private function _saveSnapshot(Tracks_Model_Entity $entity)
{
$state = clone $entity;
$state->clearAppliedEvents();
View
31 library/Tracks/EventStore/SnapshotStorage/File.php
@@ -6,30 +6,25 @@
*
* @category Tracks
* @package EventStore
- * @subpackage SnapshotStorage
+ * @subpackage Tracks_EventStore_SnapshotStorage
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore\SnapshotStorage;
-use Tracks\EventStore\ISnapshotStore;
-use Tracks\Model\Entity, Tracks\Model\Guid;
-
-
/**
* Filesystem-based Snapshot Storage
*
* @category Tracks
* @package EventStore
- * @subpackage SnapshotStorage
+ * @subpackage Tracks_EventStore_SnapshotStorage
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class File implements ISnapshotStore
+class Tracks_EventStore_SnapshotStorage_File implements Tracks_EventStore_ISnapshotStore
{
/**
@@ -48,12 +43,12 @@ public function __construct($directory)
/**
* Save an Entity
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Tracks_Model_Entity
*
* @return null
- * @see Tracks\EventStore.ISnapshotStore::save()
+ * @see Tracks_EventStore_ISnapshotStore::save()
*/
- public function save(Entity $entity)
+ public function save(Tracks_Model_Entity $entity)
{
file_put_contents(
$this->_getFilename($entity->getGuid()), serialize($entity)
@@ -63,12 +58,12 @@ public function save(Entity $entity)
/**
* Load an Entity
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return Entity|null
- * @see Tracks\EventStore.ISnapshotStore::load()
+ * @return Tracks_Model_Entity|null
+ * @see Tracks_EventStore_ISnapshotStore::load()
*/
- public function load(Guid $guid)
+ public function load(Tracks_Model_Guid $guid)
{
if (file_exists($this->_getFilename($guid))) {
return unserialize(file_get_contents($this->_getFilename($guid)));
@@ -80,11 +75,11 @@ public function load(Guid $guid)
/**
* Get the filename of an Entity by its GUID
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return string
*/
- private function _getFilename(Guid $guid)
+ private function _getFilename(Tracks_Model_Guid $guid)
{
return $this->_directory
.DIRECTORY_SEPARATOR
@@ -94,4 +89,4 @@ private function _getFilename(Guid $guid)
/** @var string */
private $_directory;
-}
+}
View
18 library/Tracks/EventStore/SnapshotStorage/Memory.php
@@ -13,10 +13,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\EventStore\SnapshotStorage;
-use \Tracks\EventStore\ISnapshotStore;
-use \Tracks\Model\Guid, \Tracks\Model\Entity;
-
/**
* In-Memory snapshot store implementation
*
@@ -28,17 +24,17 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Memory implements ISnapshotStore
+class Tracks_EventStore_SnapshotStorage_Memory implements Tracks_EventStore_ISnapshotStore
{
/**
* Load a snapshot by guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return Tracks\Model\Entity
+ * @return Tracks_Model_Entity
*/
- public function load(Guid $guid)
+ public function load(Tracks_Model_Guid $guid)
{
if (isset($this->_snapshots[(string) $guid])) {
return $this->_snapshots[(string) $guid];
@@ -50,15 +46,15 @@ public function load(Guid $guid)
/**
* Save a snapshot of an entity
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- public function save(Entity $entity)
+ public function save(Tracks_Model_Entity $entity)
{
$this->_snapshots[(string) $entity->getGuid()] = clone $entity;
}
/** @var array */
private $_snapshots = array();
-}
+}
View
10 library/Tracks/Exception/Base.php
@@ -5,25 +5,23 @@
* PHP Version 5.3
*
* @category Tracks
- * @package Exception
+ * @package Tracks_Exception
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Exception;
-
/**
* Base Tracks Exception
*
* @category Tracks
- * @package Exception
+ * @package Tracks_Exception
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Base extends Exception
+class Tracks_Exception_Base extends Tracks_Exception
{
-}
+}
View
10 library/Tracks/Exception/HandlerAlreadyRegistered.php
@@ -5,28 +5,26 @@
* PHP Version 5.3
*
* @category Tracks
- * @package Exception
+ * @package Tracks_Exception
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Exception;
-
/**
* Handler Already Registered
*
* An attempt to register an event on a domain that has already been registered.
*
* @category Tracks
- * @package Exception
+ * @package Tracks_Exception
* @author Sean Crystal <sean.crystal@gmail.com>
* @copyright 2011 Sean Crystal
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class HandlerAlreadyRegistered extends Base
+class Tracks_Exception_HandlerAlreadyRegistered extends Tracks_Exception_Base
{
/**
* Constructor
@@ -47,4 +45,4 @@ public function __construct($domainClass, $eventClass, $existingHandler)
.' for event '.$eventClass.': '.$existingHandler
);
}
-}
+}
View
4 library/Tracks/Model/AggregateRoot.php
@@ -12,8 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Model;
-
/**
* Aggregate root base class
*
@@ -27,6 +25,6 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-abstract class AggregateRoot extends Entity
+abstract class Tracks_Model_AggregateRoot extends Tracks_Model_Entity
{
}
View
29 library/Tracks/Model/Entity.php
@@ -12,9 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Model;
-use Tracks\Exception\HandlerAlreadyRegistered;
-
/**
* Domain Entity base class
*
@@ -25,7 +22,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-abstract class Entity
+abstract class Tracks_Model_Entity
{
/**
@@ -46,7 +43,7 @@ public function loadHistory(array $history)
/**
* Get this entity's guid
*
- * @return Tracks\Model\Guid
+ * @return Tracks_Model_Guid
*/
public function getGuid()
{
@@ -96,7 +93,7 @@ public function getAllAppliedEvents()
$events = array();
foreach ($this as $property) {
- if ($property instanceof Entity || $property instanceof EntityList) {
+ if ($property instanceof Tracks_Model_Entity || $property instanceof Tracks_Model_EntityList) {
$events = array_merge($events, $property->getAllAppliedEvents());
}
}
@@ -122,7 +119,7 @@ public function clearAppliedEvents()
public function clearAllAppliedEvents()
{
foreach ($this as $property) {
- if ($property instanceof Entity || $property instanceof EntityList) {
+ if ($property instanceof Entity || $property instanceof Tracks_Model_EntityList) {
$property->clearAllAppliedEvents();
}
}
@@ -160,7 +157,7 @@ public function getAllChildEntities()
$entities = array();
foreach ($this as $property) {
- if ($property instanceof Entity || $property instanceof EntityList) {
+ if ($property instanceof Entity || $property instanceof Tracks_Model_EntityList) {
$entities = array_merge($entities, $property->getAllEntities());
}
}
@@ -181,11 +178,11 @@ public function getAllEntities()
/**
* Find a handler method registered with an event and call it if it exists
*
- * @param \Tracks\Event\Base $event An Event
+ * @param Tracks_Event_Base $event An Event
*
* @return null
*/
- protected function handleDomainEvent(\Tracks\Event\Base $event)
+ protected function handleDomainEvent(Tracks_Event_Base $event)
{
if ($handler_name = $this->_getHandlerName($event)) {
$this->$handler_name($event);
@@ -195,11 +192,11 @@ protected function handleDomainEvent(\Tracks\Event\Base $event)
/**
* Apply a new event to this domain object
*
- * @param \Tracks\Event\Base $event An Event
+ * @param Tracks_Event_Base $event An Event
*
* @return null
*/
- protected function applyEvent(\Tracks\Event\Base $event)
+ protected function applyEvent(Tracks_Event_Base $event)
{
$this->handleDomainEvent($event);
$this->appliedEvents[] = $event;
@@ -220,7 +217,7 @@ protected function registerEvent($eventName, $handlerMethod)
assert('method_exists($this, $handlerMethod)');
if (isset($this->handlers[$eventName])) {
- throw new HandlerAlreadyRegistered(
+ throw new Tracks_Exception_HandlerAlreadyRegistered(
get_class($this),
$eventName,
$this->handlers[$eventName]
@@ -233,18 +230,18 @@ protected function registerEvent($eventName, $handlerMethod)
/**
* Get the name of the handler method for an event
*
- * @param \Tracks\Event\Base $event An Event
+ * @param Tracks_Event_Base $event An Event
*
* @return string
*/
- private function _getHandlerName(\Tracks\Event\Base $event)
+ private function _getHandlerName(Tracks_Event_Base $event)
{
return isset($this->handlers[get_class($event)])
? $this->handlers[get_class($event)]
: null;
}
- /** @var \Tracks\Model\Guid */
+ /** @var Tracks_Model_Guid */
protected $guid;
/** @var boolean */
View
31 library/Tracks/Model/EntityList.php
@@ -12,9 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Model;
-use Tracks\Model\Entity;
-
/**
* Entity list domain object
*
@@ -27,18 +24,18 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class EntityList
-implements \ArrayAccess, \Iterator, \Countable
+class Tracks_Model_EntityList
+implements ArrayAccess, Iterator, Countable
{
/**
* Add an entity to the list
*
- * @param Entity $entity An Entity
+ * @param Tracks_Model_Entity $entity An Entity
*
* @return null
*/
- public function add(Entity $entity)
+ public function add(Tracks_Model_Entity $entity)
{
$this->_items[(string) $entity->getGuid()] = $entity;
$this->_guids[] = (string) $entity->getGuid();
@@ -47,11 +44,11 @@ public function add(Entity $entity)
/**
* Find an entity by it's guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return Tracks\Model\Entity
*/
- public function find(Guid $guid)
+ public function find(Tracks_Model_Guid $guid)
{
if (isset($this->_items[(string) $guid])) {
return $this->_items[(string) $guid];
@@ -63,11 +60,11 @@ public function find(Guid $guid)
/**
* Remove an entity from the list by guid
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return null
*/
- public function remove(Guid $guid)
+ public function remove(Tracks_Model_Guid $guid)
{
$this->_guids = array_splice(
$this->_guids,
@@ -139,7 +136,7 @@ public function getAllEntities()
/**
* offsetExists
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return boolean
* @see ArrayAccess::offsetExists()
@@ -152,9 +149,9 @@ public function offsetExists($guid)
/**
* offsetGet
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
- * @return Entity
+ * @return Tracks_Model_Entity
* @see ArrayAccess::offsetGet()
*/
public function offsetGet($guid)
@@ -180,7 +177,7 @@ public function offsetSet($offset, $value)
/**
* offsetUnset
*
- * @param Guid $guid An Entity's GUID
+ * @param Tracks_Model_Guid $guid An Entity's GUID
*
* @return null
* @see ArrayAccess::offsetUnset()
@@ -198,7 +195,7 @@ public function offsetUnset($guid)
/**
* current
*
- * @return Entity
+ * @return Tracks_Model_Entity
* @see Iterator::current()
*/
public function current()
@@ -209,7 +206,7 @@ public function current()
/**
* key
*
- * @return Guid
+ * @return Tracks_Model_Guid
* @see Iterator::key()
*/
public function key()
View
8 library/Tracks/Model/Guid.php
@@ -12,8 +12,6 @@
* @link https://github.com/spiralout/Tracks
*/
-namespace Tracks\Model;
-
/**
* Globally-Unique Identifier (GUID) implementation
*
@@ -26,7 +24,7 @@
* @license http://www.opensource.org/licenses/BSD-3-Clause BSD 3-Clause
* @link https://github.com/spiralout/Tracks
*/
-class Guid
+class Tracks_Model_Guid
{
/**
@@ -55,11 +53,11 @@ public function __toString()
/**
* Guid factory method
*
- * @return \Tracks\Model\Guid
+ * @return Tracks_Model_Guid
*/
static public function create()
{
- return new self(Guid::uuid());
+ return new self(Tracks_Model_Guid::uuid());
}
/**

2 comments on commit 216e5b3

@omnomicon

NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!

Please sign in to comment.
Something went wrong with that request. Please try again.