-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
579 additions
and
922 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* This file is part of the prooph/snapshotter. | ||
* (c) 2015-%year% prooph software GmbH <[email protected]> | ||
* (c) 2015-%year% Sascha-Oliver Prolic <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ nbproject | |
.buildpath | ||
.DS_Store | ||
.idea | ||
.php_cs.cache | ||
.project | ||
.settings | ||
composer.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,10 @@ | ||
<?php | ||
$finder = Symfony\CS\Finder\DefaultFinder::create() | ||
->in('src') | ||
->in('tests'); | ||
$config = Symfony\CS\Config\Config::create(); | ||
$config->level(null); | ||
$config->fixers( | ||
array( | ||
'braces', | ||
'duplicate_semicolon', | ||
'elseif', | ||
'empty_return', | ||
'encoding', | ||
'eof_ending', | ||
'function_call_space', | ||
'function_declaration', | ||
'indentation', | ||
'join_function', | ||
'line_after_namespace', | ||
'linefeed', | ||
'lowercase_keywords', | ||
'parenthesis', | ||
'multiple_use', | ||
'method_argument_space', | ||
'object_operator', | ||
'php_closing_tag', | ||
'remove_lines_between_uses', | ||
'short_array_syntax', | ||
'short_tag', | ||
'standardize_not_equal', | ||
'trailing_spaces', | ||
'unused_use', | ||
'visibility', | ||
'whitespacy_lines', | ||
) | ||
); | ||
$config->finder($finder); | ||
|
||
$config = new Prooph\CS\Config\Prooph(); | ||
$config->getFinder()->in(__DIR__); | ||
|
||
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; | ||
|
||
$config->setCacheFile($cacheDir . '/.php_cs.cache'); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,30 +21,25 @@ | |
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": "~5.5|~7.0", | ||
"beberlei/assert": "~2.3", | ||
"prooph/common" : "~3.3", | ||
"prooph/event-store" : "^6.0", | ||
"prooph/event-sourcing" : "^4.0", | ||
"prooph/service-bus" : "^5.0", | ||
"prooph/event-store-bus-bridge" : "^2.0" | ||
"php": "^7.1", | ||
"prooph/event-sourcing" : "^5.0", | ||
"prooph/event-store" : "^7.0", | ||
"prooph/snapshot-store" : "^1.0" | ||
}, | ||
"require-dev" : { | ||
"container-interop/container-interop": "^1.1", | ||
"sandrokeil/interop-config": "^1.0", | ||
"fabpot/php-cs-fixer": "1.7.*", | ||
"phpunit/phpunit": "^4.8", | ||
"satooshi/php-coveralls": "dev-master", | ||
"zendframework/zend-servicemanager": "~2.6", | ||
"tobiju/bookdown-bootswatch-templates": "^0.2.0" | ||
"phpunit/phpunit": "^6.0", | ||
"phpspec/prophecy": "^1.7", | ||
"prooph/php-cs-fixer-config": "^0.1.1", | ||
"prooph/bookdown-template": "^0.2.3", | ||
"satooshi/php-coveralls": "^1.0", | ||
"malukenho/docheader": "^0.1.4" | ||
}, | ||
"suggest" : { | ||
"container-interop/container-interop": "For usage of provided factories", | ||
"sandrokeil/interop-config": "For usage of provided factories" | ||
}, | ||
"conflict": { | ||
"sandrokeil/interop-config": "<1.0" | ||
"prooph/pdo-snapshot-store": "^1.0 for PDO as Snapshot Store", | ||
"prooph/mongodb-snapshot-store": "^1.0 for MongoDB as Snapshot Store" | ||
}, | ||
"autoload" : { | ||
"psr-4" : { | ||
|
@@ -54,9 +49,15 @@ | |
"autoload-dev" : { | ||
"psr-4" : { | ||
"ProophTest\\Snapshotter\\": "tests/", | ||
"ProophTest\\EventSourcing\\": "vendor/prooph/event-sourcing/tests/", | ||
"ProophTest\\EventStore\\": "vendor/prooph/event-store/tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-develop": "2.1-dev" | ||
} | ||
}, | ||
"scripts": { | ||
"check": [ | ||
"@cs", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"title": "Snapshot tool for the prooph event-store", | ||
"title": "Prooph EventSourcing", | ||
"content": [ | ||
{"intro": "../README.md"}, | ||
{"configuration": "configuration.md"} | ||
{"snapshots": "snapshots.md"} | ||
], | ||
"target": "./html", | ||
"template": "../vendor/tobiju/bookdown-bootswatch-templates/templates/main.php" | ||
"template": "../vendor/prooph/bookdown-template/templates/main.php" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Snapshotter | ||
|
||
There are two projections shipped with this package: | ||
|
||
1) CategorySnapshotProjection | ||
2) StreamSnapshotProjection | ||
|
||
## CategorySnapshotProjection | ||
|
||
Use this one, if you are using one stream per aggregate, so when you have two users with ids `123` and `234` the event | ||
streams are named `user-123` and `user-234`, in this case you need to create the snapshots by querying the category user. | ||
|
||
## StreamSnapshotProjection | ||
|
||
Use this one, if you are using one stream for all aggregates, so when you have two users with ids `123` and `234` the event | ||
stream is simply `user` for both of them, in this case you need to create the snapshots by querying the stream user. | ||
|
||
## Usage | ||
|
||
You need to create a simple script, that might look similar to this and run it in background. | ||
With the help of docker-containers or supervisord you can keep the script alive, if it dies. | ||
|
||
```php | ||
<?php | ||
|
||
$container = include 'container.php'; | ||
|
||
$projectionManager = $container->get(\Prooph\EventStore\Projection\ProjectionManager::class); | ||
|
||
$projection = $projectionManager->createReadModelProjection( | ||
'user-snapshots', | ||
new \Prooph\Snapshotter\SnapshotReadModel( | ||
$container->get('user_repository'), | ||
new \Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator(), | ||
$container->get(\Prooph\SnapshotStore\SnapshotStore::class), | ||
[ | ||
'user', | ||
] | ||
) | ||
); | ||
|
||
$categorySnapshotProjection = new \Prooph\Snapshotter\CategorySnapshotProjection($projection, 'user'); | ||
$categorySnapshotProjection->run(); | ||
|
||
// or | ||
|
||
$streamSnapshotProjection = new \Prooph\Snapshotter\StreamSnapshotProjection($projection, 'user'); | ||
$streamSnapshotProjection->run(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* This file is part of the prooph/snapshotter. | ||
* (c) 2015-2017 prooph software GmbH <[email protected]> | ||
* (c) 2015-2017 Sascha-Oliver Prolic <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prooph\Snapshotter; | ||
|
||
use Prooph\Common\Messaging\Message; | ||
use Prooph\EventStore\Projection\ReadModelProjector; | ||
|
||
class CategorySnapshotProjection | ||
{ | ||
/** | ||
* @var ReadModelProjector | ||
*/ | ||
private $readModelProjector; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $category; | ||
|
||
public function __construct(ReadModelProjector $readModelProjector, string $category) | ||
{ | ||
$this->readModelProjector = $readModelProjector; | ||
$this->category = $category; | ||
} | ||
|
||
public function __invoke(bool $keepRunning = true) | ||
{ | ||
$this->readModelProjector | ||
->fromCategory($this->category) | ||
->whenAny(function ($state, Message $event): void { | ||
$this->readModel()->stack('replay', $event); | ||
}) | ||
->run($keepRunning); | ||
} | ||
} |
Oops, something went wrong.