-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pieter Verloop
committed
Oct 12, 2017
1 parent
7815e3d
commit d45a7a9
Showing
33 changed files
with
802 additions
and
0 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,6 @@ | ||
/vendor/ | ||
composer.lock | ||
coverage.xml | ||
tests/RapidoBundle/Config/sqlite.db | ||
tests/RapidoBundle/Config/cache/ | ||
tests/RapidoBundle/Config/logs/ |
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,13 @@ | ||
language: php | ||
|
||
php: | ||
- 7.0 | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --prefer-dist --no-interaction | ||
|
||
script: ./vendor/bin/phpunit --coverage-clover=coverage.xml | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
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,2 @@ | ||
# Avoran/Rapido | ||
[![Build Status](https://travis-ci.org/Avoran/Rapido.svg?branch=master)](https://travis-ci.org/Avoran/Rapido.svg?branch=master) [![codecov](https://codecov.io/gh/Avoran/Rapido/branch/master/graph/badge.svg)](https://codecov.io/gh/Avoran/Rapido) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Avoran/Rapido/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Avoran/Rapido/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/Avoran/Rapido/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Avoran/Rapido/?branch=master) |
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,34 @@ | ||
{ | ||
"name": "avoran/rapido", | ||
"description": "Readmodel library for event stores", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Avoran", | ||
"email": "avoran@protonmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.0", | ||
"doctrine/dbal": "^2.5", | ||
"symfony/framework-bundle": "^3.3" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Avoran\\Rapido\\": "src/Rapido", | ||
"Avoran\\RapidoAdapter\\": "src/RapidoAdapter", | ||
"Avoran\\RapidoBundle\\": "src/RapidoBundle" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Avoran\\Rapido\\": "tests/Rapido", | ||
"Avoran\\RapidoAdapter\\": "tests/RapidoAdapter", | ||
"Avoran\\RapidoBundle\\": "tests/RapidoBundle" | ||
} | ||
} | ||
} |
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,27 @@ | ||
<?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="tests/bootstrap.php" | ||
> | ||
<php> | ||
<server name="KERNEL_DIR" value="tests/RapidoBundle/Config" /> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Rapido Test Suite"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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,7 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel\DataType; | ||
|
||
final class Boolean implements FieldDataType | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel\DataType; | ||
|
||
final class DateTime implements FieldDataType | ||
{ | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel\DataType; | ||
|
||
final class Decimal implements FieldDataType | ||
{ | ||
private $totalDigits; | ||
public function getTotalDigits() { return $this->totalDigits; } | ||
|
||
private $fractionalDigits; | ||
public function getFractionalDigits() { return $this->fractionalDigits; } | ||
|
||
public function __construct($totalDigits, $fractionalDigits) | ||
{ | ||
if ($totalDigits <= $fractionalDigits) | ||
throw new \InvalidArgumentException("'totalDigits' ({$totalDigits}) has to be larger than 'fractionalDigits' ({$fractionalDigits})"); | ||
|
||
$this->totalDigits = $totalDigits; | ||
$this->fractionalDigits = $fractionalDigits; | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel\DataType; | ||
|
||
interface FieldDataType | ||
{ | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel\DataType; | ||
|
||
final class Integer implements FieldDataType | ||
{ | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel\DataType; | ||
|
||
final class TextString implements FieldDataType | ||
{ | ||
private $maxLength; | ||
public function getMaxLength() { return $this->maxLength; } | ||
|
||
public function __construct($maxLength = null) | ||
{ | ||
$this->maxLength = $maxLength; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel; | ||
|
||
final class ReadModelConfiguration | ||
{ | ||
private $name; | ||
public function getName() { return $this->name; } | ||
|
||
private $id; | ||
public function getId() { return $this->id; } | ||
|
||
/** @var ReadModelField[] */ | ||
private $fields; | ||
public function getFields() { return $this->fields; } | ||
|
||
private $recordFactory; | ||
private $allRecords; | ||
|
||
public function __construct($name, ReadModelId $id, array $fields, callable $recordFactory, callable $allRecords) | ||
{ | ||
$this->name = $name; | ||
$this->id = $id; | ||
$this->fields = $fields; | ||
$this->recordFactory = $recordFactory; | ||
$this->allRecords = $allRecords; | ||
} | ||
|
||
public function getAllRecords() | ||
{ | ||
$allRecords = $this->allRecords; | ||
foreach ($allRecords() as $recordData) | ||
yield $recordData; | ||
} | ||
|
||
/** @return Record */ | ||
public function createRecord($recordData) | ||
{ | ||
$recordFactory = $this->recordFactory; | ||
return $recordFactory($recordData); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel; | ||
|
||
use Avoran\Rapido\ReadModel\DataType\FieldDataType; | ||
|
||
final class ReadModelField | ||
{ | ||
private $id; | ||
public function getId() { return $this->id; } | ||
|
||
private $dataType; | ||
public function getDataType() { return $this->dataType; } | ||
|
||
public function __construct($id, FieldDataType $dataType) | ||
{ | ||
$this->id = $id; | ||
$this->dataType = $dataType; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel; | ||
|
||
use Avoran\Rapido\ReadModel\DataType\FieldDataType; | ||
|
||
final class ReadModelId | ||
{ | ||
private $dataType; | ||
public function getDataType() { return $this->dataType; } | ||
|
||
public function __construct(FieldDataType $dataType) | ||
{ | ||
$this->dataType = $dataType; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel; | ||
|
||
final class Record | ||
{ | ||
private $id; | ||
public function getId() { return $this->id; } | ||
|
||
private $data; | ||
public function getData() { return $this->data; } | ||
|
||
public function __construct($id, $data) | ||
{ | ||
$this->id = $id; | ||
$this->data = $data; | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
namespace Avoran\Rapido\ReadModel; | ||
|
||
interface StorageWriter | ||
{ | ||
public function writeRecord(ReadModelConfiguration $metadata, $recordData); | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Avoran\RapidoAdapter\DoctrineDbalStorage; | ||
|
||
use Doctrine\DBAL\Schema\Column; | ||
use Avoran\Rapido\ReadModel\DataType\FieldDataType; | ||
|
||
class ColumnFactory | ||
{ | ||
private $dbalTypeMapper; | ||
private $dbalOptionsMapper; | ||
|
||
public function __construct(DbalTypeMapper $dbalTypeMapper, DbalOptionsMapper $dbalOptionsMapper) | ||
{ | ||
$this->dbalTypeMapper = $dbalTypeMapper; | ||
$this->dbalOptionsMapper = $dbalOptionsMapper; | ||
} | ||
|
||
public function createColumn(FieldDataType $dataType, $id) | ||
{ | ||
return new Column( | ||
$id, | ||
$this->dbalTypeMapper->mapReadModelToDbalType($dataType), | ||
$this->dbalOptionsMapper->mapReadModelToDbalOptions($dataType) | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/RapidoAdapter/DoctrineDbalStorage/DbalOptionsMapper.php
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,22 @@ | ||
<?php | ||
|
||
namespace Avoran\RapidoAdapter\DoctrineDbalStorage; | ||
|
||
use Avoran\Rapido\ReadModel\DataType\Decimal; | ||
use Avoran\Rapido\ReadModel\DataType\FieldDataType; | ||
|
||
class DbalOptionsMapper | ||
{ | ||
public function mapReadModelToDbalOptions(FieldDataType $fieldDataType) | ||
{ | ||
$options = ['notnull' => false]; | ||
|
||
switch ($fieldDataType) { | ||
case $fieldDataType instanceof Decimal: | ||
$options = array_merge($options, ['scale' => $fieldDataType->getFractionalDigits(), 'precision' => $fieldDataType->getTotalDigits()]); | ||
break; | ||
} | ||
|
||
return $options; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Avoran\RapidoAdapter\DoctrineDbalStorage; | ||
|
||
use Doctrine\DBAL\Types\Type; | ||
use Avoran\Rapido\ReadModel\DataType\Boolean; | ||
use Avoran\Rapido\ReadModel\DataType\DateTime; | ||
use Avoran\Rapido\ReadModel\DataType\Decimal; | ||
use Avoran\Rapido\ReadModel\DataType\FieldDataType; | ||
use Avoran\Rapido\ReadModel\DataType\Integer; | ||
use Avoran\Rapido\ReadModel\DataType\TextString; | ||
|
||
class DbalTypeMapper | ||
{ | ||
public function mapReadModelToDbalType(FieldDataType $fieldDataType) | ||
{ | ||
switch ($fieldDataType) { | ||
case $fieldDataType instanceof Integer: | ||
return Type::getType(Type::INTEGER); | ||
case $fieldDataType instanceof Decimal: | ||
return Type::getType(Type::DECIMAL); | ||
case $fieldDataType instanceof Boolean: | ||
return Type::getType(Type::BOOLEAN); | ||
case $fieldDataType instanceof TextString: | ||
return $fieldDataType->getMaxLength() && $fieldDataType->getMaxLength() < 256 | ||
? Type::getType(Type::STRING) | ||
: Type::getType(Type::TEXT) | ||
; | ||
case $fieldDataType instanceof DateTime: | ||
return Type::getType(Type::DATETIME); | ||
default: | ||
throw new \InvalidArgumentException("Could not find a suitable data type"); | ||
} | ||
} | ||
} |
Oops, something went wrong.