Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prooph/pdo-snapshot-store
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e1159674fc127c5a9463802ce35c07c22f14734f
Choose a base ref
...
head repository: prooph/pdo-snapshot-store
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.0-beta1
Choose a head ref
  • 17 commits
  • 14 files changed
  • 1 contributor

Commits on Dec 2, 2016

  1. add implementation and tests

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    a7f2066 View commit details
  2. fix travis yml

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    77c02f3 View commit details
  3. fix travis yml

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    d0de92f View commit details
  4. apply php cs fixes

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    ff632ea View commit details
  5. fix travis build

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    f879f86 View commit details
  6. fix composer json

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    819a73d View commit details
  7. add container factory + test

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    720c454 View commit details
  8. add missing license header

    prolic committed Dec 2, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    104f8ef View commit details

Commits on Dec 4, 2016

  1. cleanup tests

    prolic committed Dec 4, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    4f20616 View commit details

Commits on Dec 5, 2016

  1. Update composer.json

    prolic authored Dec 5, 2016
    Copy the full SHA
    1115219 View commit details
  2. Merge pull request #1 from prooph/implementation

    add implementation and tests
    prolic authored Dec 5, 2016
    Copy the full SHA
    e187161 View commit details

Commits on Dec 10, 2016

  1. update to interop-config 2.0.1

    prolic committed Dec 10, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    eebd622 View commit details

Commits on Dec 13, 2016

  1. update composer deps

    prolic committed Dec 13, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    284ab4d View commit details
  2. update composer deps

    prolic committed Dec 13, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    fc3c251 View commit details
  3. update composer json

    prolic committed Dec 13, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    a1a516a View commit details
  4. update composer suggest

    prolic committed Dec 13, 2016

    Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    a6d4940 View commit details
  5. Verified

    This commit was signed with the committer’s verified signature. The key has been revoked.
    prolic Sascha-Oliver Prolić
    Copy the full SHA
    04687c3 View commit details
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -6,4 +6,6 @@
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
.travis.install-mysql-5.7.sh export-ignore
phpunit.xml.pdo_mysql export-ignore
phpunit.xml.pdo_pgsql export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
/vendor
/build
.idea
phpunit.xml
.php_cs.cache
nbproject
composer.lock
6 changes: 6 additions & 0 deletions .travis.install-mysql-5.7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo debconf-set-selections
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg --install mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update -q
sudo apt-get install -q -y -o Dpkg::Options::=--force-confnew mysql-server
sudo mysql_upgrade
64 changes: 64 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -4,13 +4,73 @@ matrix:
fast_finish: true
include:
- php: 7.1
env:
- DEPENDENCIES=""
- DRIVER="pdo_mysql"
- DB=mysql_5_6
- php: 7.1
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- DRIVER="pdo_mysql"
- DB=mysql_5_6
- php: 7.1
sudo: true
env:
- DEPENDENCIES=""
- DRIVER="pdo_mysql"
- DB=mysql_5.7
- php: 7.1
sudo: true
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- DRIVER="pdo_mysql"
- DB=mysql_5.7
- php: 7.1
env:
- DEPENDENCIES=""
- DRIVER="pdo_pgsql"
- DB=postgres_9.3
addons:
postgresql: '9.3'
- php: 7.1
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- DRIVER="pdo_pgsql"
- DB=postgres_9.3
addons:
postgresql: '9.3'
- php: 7.1
env:
- DEPENDENCIES=""
- DRIVER="pdo_pgsql"
- DB=postgres_9.4
addons:
postgresql: '9.4'
- php: 7.1
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- DRIVER="pdo_pgsql"
- DB=postgres_9.4
addons:
postgresql: '9.4'
- php: 7.1
dist: trusty
env:
- DEPENDENCIES=""
- EXECUTE_CS_CHECK=true
- TEST_COVERAGE=true
- DRIVER="pdo_pgsql"
- DB=postgres_9.5
addons:
postgresql: '9.5'
- php: 7.1
dist: trusty
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- DRIVER="pdo_pgsql"
- DB=postgres_9.5
addons:
postgresql: '9.5'

cache:
directories:
@@ -21,10 +81,14 @@ cache:
before_script:
- mkdir -p "$HOME/.php-cs-fixer"
- phpenv config-rm xdebug.ini
- if [[ $DB == 'mysql_5.7' ]]; then bash .travis.install-mysql-5.7.sh; fi
- if [[ $DRIVER == 'pdo_mysql' ]]; then mysql -e 'create database snapshot_tests;'; fi
- if [[ $DRIVER == 'pdo_pgsql' ]]; then psql -c 'create database snapshot_tests;' -U postgres; fi
- composer self-update
- composer update --prefer-dist $DEPENDENCIES

script:
- cp phpunit.xml.$DRIVER phpunit.xml
- 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
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -25,36 +25,36 @@
"prefer-stable": true,
"require": {
"php": "^7.1",
"prooph/event-sourcing" : "5.0.x-dev"
"prooph/event-sourcing" : "^5.0.0-beta"
},
"require-dev": {
"container-interop/container-interop": "^1.1",
"sandrokeil/interop-config": "^1.0",
"phpunit/phpunit": "^5.6",
"phpunit/phpunit-mock-objects": "^3.3.1",
"phpspec/prophecy": "dev-patch-1 as 1.6.1",
"sandrokeil/interop-config": "^2.0.1",
"phpunit/phpunit": "^5.7.3",
"phpspec/prophecy": "dev-patch-1 as 1.6.2",
"prooph/php-cs-fixer-config": "^0.1.1",
"satooshi/php-coveralls": "^1.0",
"zendframework/zend-servicemanager": "~2.6",
"sebastian/comparator": "^1.2.2",
"zendframework/zend-servicemanager": "^3.1",
"malukenho/docheader": "^0.1.4"
},
"suggest" : {
"prooph/pdo-event-store": "For usage with MySQL or Postgres as event store",
"prooph/service-bus" : "Message bus facade to connect the event store with messaging systems",
"prooph/pdo-event-store": "^1.0 For usage with MySQL or Postgres as event store",
"prooph/snapshotter": "^2.0 Taking snapshots with ease",
"container-interop/container-interop": "For usage of provided factories",
"sandrokeil/interop-config": "For usage of provided factories"
},
"conflict": {
"sandrokeil/interop-config": "<1.0"
"sandrokeil/interop-config": "<2.0.1"
},
"autoload": {
"psr-4": {
"Prooph\\PDOSnapshotStore\\": "src/"
"Prooph\\PDO\\SnapshotStore\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ProophTest\\PDOSnapshotStore\\": "tests/"
"ProophTest\\PDO\\SnapshotStore\\": "tests/"
}
},
"extra": {
9 changes: 9 additions & 0 deletions phpunit.xml.dist → phpunit.xml.pdo_mysql
Original file line number Diff line number Diff line change
@@ -20,4 +20,13 @@
<directory>./src/</directory>
</whitelist>
</filter>

<php>
<var name="db_type" value="pdo_mysql"/>
<var name="db_host" value="127.0.0.1" />
<var name="db_username" value="root" />
<var name="db_password" value="" />
<var name="db_name" value="snapshot_tests" />
<var name="db_port" value="3306"/>
</php>
</phpunit>
32 changes: 32 additions & 0 deletions phpunit.xml.pdo_pgsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuite name="Prooph PDO Snapshot Store Test Suite">
<directory>./tests</directory>
</testsuite>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>

<php>
<var name="db_type" value="pdo_pgsql"/>
<var name="db_host" value="localhost" />
<var name="db_username" value="postgres" />
<var name="db_password" value="" />
<var name="db_name" value="snapshot_tests" />
<var name="db_port" value="5432"/>
</php>
</phpunit>
8 changes: 8 additions & 0 deletions scripts/mysql_snapshot_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE `snapshots` (
`aggregate_id` VARCHAR(150) NOT NULL,
`aggregate_type` VARCHAR(150) NOT NULL,
`last_version` INT(11) NOT NULL,
`created_at` CHAR(26) NOT NULL,
`aggregate_root` BLOB,
UNIQUE KEY `ix_aggregate_id` (`aggregate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
8 changes: 8 additions & 0 deletions scripts/postgres_snapshot_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE snapshots (
aggregate_id VARCHAR(150) NOT NULL,
aggregate_type VARCHAR(150) NOT NULL,
last_version INT NOT NULL,
created_at CHAR(26) NOT NULL,
aggregate_root BYTEA,
UNIQUE (aggregate_id)
);
121 changes: 121 additions & 0 deletions src/Container/PDOSnapshotStoreFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* This file is part of the prooph/pdo-snapshot-store.
* (c) 2016-2016 prooph software GmbH <contact@prooph.de>
* (c) 2016-2016 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
*
* 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\PDO\SnapshotStore\Container;

use Interop\Config\ConfigurationTrait;
use Interop\Config\ProvidesDefaultOptions;
use Interop\Config\RequiresConfigId;
use Interop\Container\ContainerInterface;
use PDO;
use Prooph\PDO\SnapshotStore\PDOSnapshotStore;

class PDOSnapshotStoreFactory implements ProvidesDefaultOptions, RequiresConfigId
{
use ConfigurationTrait;

/**
* @var string
*/
private $configId;

/**
* @var array
*/
private $driverSchemeAliases = [
'pdo_mysql' => 'mysql',
'pdo_pgsql' => 'pgsql',
];

private $driverSchemeSeparators = [
'pdo_mysql' => ';',
'pdo_pgsql' => ' ',
];

/**
* Creates a new instance from a specified config, specifically meant to be used as static factory.
*
* In case you want to use another config key than provided by the factories, you can add the following factory to
* your config:
*
* <code>
* <?php
* return [
* PDOSnapshotStore::class => [PDOSnapshotStoreFactory::class, 'service_name'],
* ];
* </code>
*
* @throws \InvalidArgumentException
*/
public static function __callStatic(string $name, array $arguments): PDOSnapshotStore
{
if (! isset($arguments[0]) || ! $arguments[0] instanceof ContainerInterface) {
throw new \InvalidArgumentException(
sprintf('The first argument must be of type %s', ContainerInterface::class)
);
}

return (new static($name))->__invoke($arguments[0]);
}

public function __invoke(ContainerInterface $container): PDOSnapshotStore
{
$config = $container->get('config');
$config = $this->options($config, $this->configId);

if (isset($config['connection_service'])) {
$connection = $container->get($config['connection_service']);
} else {
$separator = $this->driverSchemeSeparators[$config['connection_options']['driver']];
$dsn = $this->driverSchemeAliases[$config['connection_options']['driver']] . ':';
$dsn .= 'host=' . $config['connection_options']['host'] . $separator;
$dsn .= 'port=' . $config['connection_options']['port'] . $separator;
$dsn .= 'dbname=' . $config['connection_options']['dbname'] . $separator;
$dsn = rtrim($dsn);
$user = $config['connection_options']['user'];
$password = $config['connection_options']['password'];
$connection = new PDO($dsn, $user, $password);
}

return new PDOSnapshotStore(
$connection,
$config['snapshot_table_map'],
$config['default_snapshot_table_name']
);
}

public function __construct(string $configId = 'default')
{
$this->configId = $configId;
}

public function dimensions(): iterable
{
return ['prooph', 'pdo_snapshot_store'];
}

public function defaultOptions(): iterable
{
return [
'connection_options' => [
'driver' => 'pdo_mysql', // or use pdo_pgsql
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'dbname' => 'snapshot_store',
'port' => 3306, // or use 5432 for pgsql (default)
],
'snapshot_table_map' => [],
'default_snapshot_table_name' => 'snapshots',
];
}
}
Loading