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
1 parent
c2865e2
commit 8d4810c
Showing
12 changed files
with
783 additions
and
3 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
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 | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes\Exceptions; | ||
|
||
/** | ||
* | ||
*/ | ||
final class EmptyValuesNotAllowed extends \InvalidArgumentException | ||
{ | ||
|
||
} |
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 | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes\Exceptions; | ||
|
||
/** | ||
* | ||
*/ | ||
final class IndexNameCantBeEmpty extends \InvalidArgumentException | ||
{ | ||
|
||
} |
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 | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes\Exceptions; | ||
|
||
/** | ||
* | ||
*/ | ||
final class InvalidValueType extends \InvalidArgumentException | ||
{ | ||
|
||
} |
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 | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes\Exceptions; | ||
|
||
/** | ||
* | ||
*/ | ||
final class ValueKeyCantBeEmpty extends \InvalidArgumentException | ||
{ | ||
|
||
} |
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,92 @@ | ||
<?php | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes; | ||
|
||
use ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty; | ||
use ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty; | ||
|
||
/** | ||
* The key for the value stored in the index | ||
* | ||
* @property-read string $indexName | ||
* @property-read string $valueKey | ||
*/ | ||
final class IndexKey | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $indexName; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $valueKey; | ||
|
||
/** | ||
* @param string $indexName | ||
* @param string $valueKey | ||
* | ||
* @return self | ||
* | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty | ||
*/ | ||
public static function create(string $indexName, string $valueKey): self | ||
{ | ||
self::assertIndexNameIsNotEmpty($indexName); | ||
self::assertValueKeyIsNotEmpty($valueKey); | ||
|
||
return new self($indexName, $valueKey); | ||
} | ||
|
||
/** | ||
* @param string $indexName | ||
* | ||
* @return void | ||
* | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\IndexNameCantBeEmpty | ||
*/ | ||
private static function assertIndexNameIsNotEmpty(string $indexName): void | ||
{ | ||
if('' === $indexName) | ||
{ | ||
throw new IndexNameCantBeEmpty('Index name can\'t be empty'); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $valueKey | ||
* | ||
* @return void | ||
* | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\ValueKeyCantBeEmpty | ||
*/ | ||
private static function assertValueKeyIsNotEmpty(string $valueKey): void | ||
{ | ||
if('' === $valueKey) | ||
{ | ||
throw new ValueKeyCantBeEmpty('Value key can\'t be empty'); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $indexName | ||
* @param string $valueKey | ||
*/ | ||
private function __construct(string $indexName, string $valueKey) | ||
{ | ||
$this->indexName = $indexName; | ||
$this->valueKey = $valueKey; | ||
} | ||
} |
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,85 @@ | ||
<?php | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes; | ||
|
||
use ServiceBus\EventSourcing\Indexes\Exceptions\EmptyValuesNotAllowed; | ||
use ServiceBus\EventSourcing\Indexes\Exceptions\InvalidValueType; | ||
|
||
/** | ||
* The value stored in the index | ||
* | ||
* @property-read mixed $value | ||
*/ | ||
final class IndexValue | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
public $value; | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return self | ||
* | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\InvalidValueType | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\EmptyValuesNotAllowed | ||
*/ | ||
public static function create($value): self | ||
{ | ||
self::assertIsScalar($value); | ||
self::assertNotEmpty($value); | ||
|
||
return new self($value); | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return void | ||
* | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\EmptyValuesNotAllowed | ||
*/ | ||
private static function assertNotEmpty($value): void | ||
{ | ||
if('' === (string) $value) | ||
{ | ||
throw new EmptyValuesNotAllowed('Value can not be empty'); | ||
} | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return void | ||
* | ||
* @throws \ServiceBus\EventSourcing\Indexes\Exceptions\InvalidValueType | ||
*/ | ||
private static function assertIsScalar($value): void | ||
{ | ||
if(false === \is_scalar($value)) | ||
{ | ||
throw new InvalidValueType( | ||
\sprintf('The value must be of type "scalar". "%s" passed', \gettype($value)) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
private function __construct($value) | ||
{ | ||
$this->value = $value; | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
/** | ||
* Event Sourcing implementation | ||
* | ||
* @author Maksim Masiukevich <dev@async-php.com> | ||
* @license MIT | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ServiceBus\EventSourcing\Indexes\Store; | ||
|
||
use Amp\Promise; | ||
use ServiceBus\EventSourcing\Indexes\IndexKey; | ||
use ServiceBus\EventSourcing\Indexes\IndexValue; | ||
|
||
/** | ||
* | ||
*/ | ||
interface IndexStore | ||
{ | ||
/** | ||
* Find stored value | ||
* | ||
* @param IndexKey $indexKey | ||
* | ||
* @return Promise<\ServiceBus\EventSourcing\Indexes\IndexValue|null> | ||
* | ||
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions | ||
*/ | ||
public function find(IndexKey $indexKey): Promise; | ||
|
||
/** | ||
* Add a new value | ||
* | ||
* @param IndexKey $indexKey | ||
* @param IndexValue $value $value | ||
* | ||
* @return Promise<int> Returns the number of added records | ||
* | ||
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions | ||
* @throws \ServiceBus\Storage\Common\Exceptions\UniqueConstraintViolationCheckFailed | ||
*/ | ||
public function add(IndexKey $indexKey, IndexValue $value): Promise; | ||
|
||
/** | ||
* @param IndexKey $indexKey | ||
* | ||
* @return Promise It doesn't return any result | ||
* | ||
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions | ||
*/ | ||
public function delete(IndexKey $indexKey): Promise; | ||
|
||
/** | ||
* Update existent value | ||
* | ||
* @param IndexKey $indexKey | ||
* @param IndexValue $value | ||
* | ||
* @return Promise<int> Returns the number of updated records | ||
* | ||
* @throws \ServiceBus\Storage\Common\Exceptions\ConnectionFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\StorageInteractingFailed | ||
* @throws \ServiceBus\Storage\Common\Exceptions\InvalidConfigurationOptions | ||
*/ | ||
public function update(IndexKey $indexKey, IndexValue $value): Promise; | ||
} |
Oops, something went wrong.