Permalink
Browse files

Initial commit

  • Loading branch information...
codeliner committed Apr 19, 2014
0 parents commit b5986d2493843b7d31ad7482bb4725cc3007a072
Showing with 2,697 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +11 −0 .travis.yml
  3. +27 −0 LICENSE.txt
  4. +34 −0 README.md
  5. +47 −0 composer.json
  6. +44 −0 src/Prooph/EventStore/Adapter/AdapterInterface.php
  7. +55 −0 src/Prooph/EventStore/Adapter/Builder/AggregateIdBuilder.php
  8. +28 −0 src/Prooph/EventStore/Adapter/Builder/AggregateIdType.php
  9. +74 −0 src/Prooph/EventStore/Adapter/Builder/EventBuilder.php
  10. +24 −0 src/Prooph/EventStore/Adapter/Exception/AdapterException.php
  11. +23 −0 src/Prooph/EventStore/Adapter/Exception/ConfigurationException.php
  12. +23 −0 src/Prooph/EventStore/Adapter/Exception/InvalidArgumentException.php
  13. +23 −0 src/Prooph/EventStore/Adapter/Feature/TransactionFeatureInterface.php
  14. +322 −0 src/Prooph/EventStore/Adapter/Zf2/Zf2EventStoreAdapter.php
  15. +138 −0 src/Prooph/EventStore/Configuration/Configuration.php
  16. +28 −0 src/Prooph/EventStore/Configuration/Exception/ConfigurationException.php
  17. +111 −0 src/Prooph/EventStore/EventSourcing/AggregateChangedEvent.php
  18. +177 −0 src/Prooph/EventStore/EventSourcing/EventSourcedAggregateRoot.php
  19. +25 −0 src/Prooph/EventStore/EventSourcing/Exception/IdentifierPropertyNotFoundException.php
  20. +25 −0 src/Prooph/EventStore/EventSourcing/Exception/NoHandlerFoundException.php
  21. +291 −0 src/Prooph/EventStore/EventStore.php
  22. +23 −0 src/Prooph/EventStore/Exception/EventStoreException.php
  23. +23 −0 src/Prooph/EventStore/Exception/InvalidArgumentException.php
  24. +23 −0 src/Prooph/EventStore/Exception/RuntimeException.php
  25. +47 −0 src/Prooph/EventStore/LifeCycleEvent/DetermineEventHandler.php
  26. +36 −0 src/Prooph/EventStore/LifeCycleEvent/GetIdentifierProperty.php
  27. +64 −0 src/Prooph/EventStore/Mapping/AggregateRootDecorator.php
  28. +65 −0 src/Prooph/EventStore/Mapping/OnEventNameHandlerStrategy.php
  29. +88 −0 src/Prooph/EventStore/Repository/EventSourcingRepository.php
  30. +54 −0 src/Prooph/EventStore/Repository/RepositoryInterface.php
  31. +66 −0 tests/Prooph/EventStoreTest/Adapter/Zf2/Zf2EventStoreAdapterTest.php
  32. +77 −0 tests/Prooph/EventStoreTest/EventSourcing/AggregateChangedEventTest.php
  33. +88 −0 tests/Prooph/EventStoreTest/EventSourcing/EventSourcedAggregateRootTest.php
  34. +86 −0 tests/Prooph/EventStoreTest/EventStoreTest.php
  35. +76 −0 tests/Prooph/EventStoreTest/Mapping/AggregateRootDecoratorTest.php
  36. +110 −0 tests/Prooph/EventStoreTest/Mock/User.php
  37. +40 −0 tests/Prooph/EventStoreTest/Mock/UserCreated.php
  38. +32 −0 tests/Prooph/EventStoreTest/Mock/UserNameChanged.php
  39. +64 −0 tests/Prooph/EventStoreTest/Repository/EventSourcingRepositoryTest.php
  40. +77 −0 tests/Prooph/EventStoreTest/TestCase.php
  41. +13 −0 tests/bootstrap.php
  42. +9 −0 tests/phpunit.xml.dist
@@ -0,0 +1,6 @@
/.settings
/.project
/.buildpath
/vendor
.idea
nbproject
@@ -0,0 +1,11 @@
language: php
php:
- 5.4
before_script:
- composer self-update
- composer update
script:
- php ./vendor/bin/phpunit -c ./tests/.
@@ -0,0 +1,27 @@
Copyright (c) 2014, Alexander Miertsch kontakt@codeliner.ws
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Alexander Miertsch nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,34 @@
ProophEventStore
===================
PHP 5.4+ EventSourcing library.
##Features
- Event driven library [in progress]
- Full DDD support [in progress]
- Collection based repositories [done]
- Support for ValueObjects as AggregateRoot identifiers [done]
- Transaction handling [done]
- Optional snapshot strategies [not started]
- Optional concurrent logging [not started]
- Link your own event dispatcher and/or connect ProophServiceBus [not started]
- Changeable storage adapter like
-- ZF2 Tablegateway [in progress]
-- doctrine dbal [not started]
-- mongoDB [not started]
-- geteventstore client [not started]
##ZF2 insight
The ProophEventStore is based on ZF2 components which offer a lot of customization options.
##Quick start
coming soon ...
##Contribution
coming soon ...
##Wiki
coming soon ...
@@ -0,0 +1,47 @@
{
"name": "prooph/event-store",
"description": "PHP EventStore library",
"type": "library",
"license": "BSD-3-Clause",
"homepage": "https://github.com/prooph/event-store/",
"authors": [
{
"name": "Alexander Miertsch",
"email": "contact@prooph.de",
"homepage": "http://www.prooph.de/"
}
],
"keywords": [
"php",
"EventSourcing",
"EventStore",
"library",
"DDD",
"prooph",
"zf2"
],
"require": {
"php": ">=5.4",
"rhumsaa/uuid" : "2.5.*",
"codeliner/php-equalsbuilder": "1.1.*",
"codeliner/array-reader": "1.0.*",
"codeliner/shared-domain-set": "1.2.*",
"beberlei/assert": "*",
"zendframework/zend-servicemanager" : "2.3.*",
"zendframework/zend-eventmanager" : "2.3.*",
"zendframework/zend-db" : "2.3.*",
"zendframework/zend-serializer" : "2.3.*"
},
"suggest": {
"doctrine/dbal": "Use Doctrine\\DBAL as EventStore-Adapter"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": {
"Prooph\\EventStore\\": "src/",
"Prooph\\EventStoreTest\\": "tests/"
}
}
}
@@ -0,0 +1,44 @@
<?php
/*
* This file is part of the prooph/event-store package.
* (c) Alexander Miertsch <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Prooph\EventStore\Adapter;
use Prooph\EventStore\EventSourcing\AggregateChangedEvent;
/**
* Interface of an EventStore Adapter
*
* @author Alexander Miertsch <contact@prooph.de>
* @package Prooph\EventStore\Adapter
*/
interface AdapterInterface
{
/**
* Load EventStream of an EventSourcedAggregateRoot from given version on
*
* Pass null as version to get the complete stream
*
* @param string $aggregateFQCN
* @param string $aggregateId
* @param int $version
*
* @return AggregateChangedEvent[]
*/
public function loadStream($aggregateFQCN, $aggregateId, $version = null);
/**
* Add events to the source stream
*
* @param string $aggregateFQCN
* @param string $aggregateId
* @param AggregateChangedEvent[] $events
*
* @return void
*/
public function addToStream($aggregateFQCN, $aggregateId, $events);
}
@@ -0,0 +1,55 @@
<?php
/*
* This file is part of the prooph/event-store.
* (c) Alexander Miertsch <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 17.04.14 - 22:41
*/
namespace Prooph\EventStore\Adapter\Builder;
/**
* Class AggregateIdBuilder
*
* @package Prooph\EventStore\Adapter\Builder
* @author Alexander Miertsch <contact@prooph.de>
*/
class AggregateIdBuilder
{
protected static $typeMap = array();
/**
* @param string $aggregateIdFQCN
* @param string $typeFQCN
*/
public static function registerType($aggregateIdFQCN, $typeFQCN)
{
static::$typeMap[$aggregateIdFQCN] = $typeFQCN;
}
/**
* @param mixed $aggregateId
* @return string
*/
public static function toString($aggregateId)
{
if (is_string($aggregateId)) {
return $aggregateId;
}
if (is_object($aggregateId)) {
if (isset(static::$typeMap[get_class($aggregateId)])) {
$typeClass = static::$typeMap[get_class($aggregateId)];
$type = new $typeClass();
return $type->convertToString($aggregateId);
}
}
return (string)$aggregateId;
}
}
@@ -0,0 +1,28 @@
<?php
/*
* This file is part of the prooph/event-store.
* (c) Alexander Miertsch <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 17.04.14 - 22:44
*/
namespace Prooph\EventStore\Adapter\Builder;
/**
* Interface AggregateIdType
*
* @package Prooph\EventStore\Adapter\Builder
* @author Alexander Miertsch <contact@prooph.de>
*/
interface AggregateIdType
{
/**
* @param mixed $aggregateId
* @return string
*/
public function convertToString($aggregateId);
}
@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the prooph/event-store.
* (c) Alexander Miertsch <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 17.04.14 - 20:56
*/
namespace Prooph\EventStore\Adapter\Builder;
use Prooph\EventStore\EventSourcing\AggregateChangedEvent;
use Rhumsaa\Uuid\Uuid;
use ValueObjects\DateTime\DateTime;
/**
* Class EventBuilder
*
* @package Prooph\EventStore\Adapter\Builder
* @author Alexander Miertsch <contact@prooph.de>
*/
class EventBuilder
{
/**
* @param string $eventFQCN
* @param Uuid $uuid
* @param mixed $aggregateId
* @param DateTime $occurredOn
* @param int $version
* @param array $payload
* @return AggregateChangedEvent
*/
public static function reconstructEvent($eventFQCN, Uuid $uuid, $aggregateId, DateTime $occurredOn, $version, array $payload)
{
$eventRef = new \ReflectionClass($eventFQCN);
$event = $eventRef->newInstanceWithoutConstructor();
$uuidProp = $eventRef->getProperty('uuid');
$uuidProp->setAccessible(true);
$uuidProp->setValue($event, $uuid);
$aggregateIdProp = $eventRef->getProperty('aggregateId');
$aggregateIdProp->setAccessible(true);
$aggregateIdProp->setValue($event, $aggregateId);
$occurredOnProp = $eventRef->getProperty('occurredOn');
$occurredOnProp->setAccessible(true);
$occurredOnProp->setValue($event, $occurredOn);
$versionProp = $eventRef->getProperty('version');
$versionProp->setAccessible(true);
$versionProp->setValue($event, $version);
$payloadProp = $eventRef->getProperty('payload');
$payloadProp->setAccessible(true);
$payloadProp->setValue($event, $payload);
return $event;
}
}
@@ -0,0 +1,24 @@
<?php
/*
* This file is part of the prooph/event-store.
* (c) Alexander Miertsch <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 17.04.14 - 20:40
*/
namespace Prooph\EventStore\Adapter\Exception;
use Prooph\EventStore\Exception\EventStoreException;
/**
* Marker interface AdapterException
*
* @package Prooph\EventStore\Adapter\Exception
* @author Alexander Miertsch <contact@prooph.de>
*/
interface AdapterException extends EventStoreException
{
}
@@ -0,0 +1,23 @@
<?php
/*
* This file is part of the prooph/event-store.
* (c) Alexander Miertsch <contact@prooph.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Date: 17.04.14 - 20:41
*/
namespace Prooph\EventStore\Adapter\Exception;
/**
* Class ConfigurationException
*
* @package Prooph\EventStore\Adapter\Exception
* @author Alexander Miertsch <contact@prooph.de>
*/
class ConfigurationException extends \RuntimeException implements AdapterException
{
}
Oops, something went wrong.

0 comments on commit b5986d2

Please sign in to comment.