Skip to content

Commit

Permalink
merged with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Mar 30, 2017
2 parents a8ffbff + 562f139 commit 3440281
Show file tree
Hide file tree
Showing 27 changed files with 579 additions and 922 deletions.
8 changes: 8 additions & 0 deletions .docheader
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.
*/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ nbproject
.buildpath
.DS_Store
.idea
.php_cs.cache
.project
.settings
composer.lock
Expand Down
44 changes: 8 additions & 36 deletions .php_cs
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;
28 changes: 19 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
language: php

php:
- 5.5
- 5.6
- 7
matrix:
fast_finish: true
include:
- php: 7.1
env:
- DEPENDENCIES=""
- EXECUTE_CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.1
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"

before_script:
- mkdir -p "$HOME/.php-cs-fixer"
- phpenv config-rm xdebug.ini
- composer self-update
- composer --dev install --prefer-source
- composer update --prefer-source $DEPENDENCIES

script:
- php ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml
- ./vendor/bin/php-cs-fixer fix -v --diff --dry-run
- if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml; else ./vendor/bin/phpunit; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/docheader check src/ tests/; fi

after_script:
- php vendor/bin/coveralls -v
after_success:
- if [[ $TEST_COVERAGE == 'true' ]]; then php vendor/bin/coveralls -v; fi

notifications:
webhooks:
Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2014-2015, prooph software GmbH
Copyright (c) 2015-2017, prooph software GmbH
Copyright (c) 2015-2017, Sascha-Oliver Prolic
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ Take aggregate snapshots with ease
[![Coverage Status](https://coveralls.io/repos/prooph/snapshotter/badge.svg?branch=master&service=github)](https://coveralls.io/github/prooph/snapshotter?branch=master)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/prooph/improoph)

## Documentation

Documentation is [in the doc tree](docs/), and can be compiled using [bookdown](http://bookdown.io).

```console
$ php ./vendor/bin/bookdown docs/bookdown.json
$ php -S 0.0.0.0:8080 -t docs/html/
```

Then browse to [http://localhost:8080/](http://localhost:8080/)

## Support

- Ask questions on [prooph-users](https://groups.google.com/forum/?hl=de#!forum/prooph) google group.
Expand Down
39 changes: 20 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand All @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions docs/bookdown.json
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"
}
39 changes: 0 additions & 39 deletions docs/configuration.md

This file was deleted.

49 changes: 49 additions & 0 deletions docs/snapshots.md
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();
```
45 changes: 45 additions & 0 deletions src/CategorySnapshotProjection.php
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);
}
}
Loading

0 comments on commit 3440281

Please sign in to comment.