Completed
Pull Request — master (#37)
by Alessandro
03:48 queued 57s
created

DynamoDb   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDriver() 0 26 1
1
<?php namespace Nwidart\LaravelBroadway\EventStore\Broadway\Drivers;
2
3
use Aws\DynamoDb\DynamoDbClient;
4
use Broadway\EventStore\DynamoDb\DynamoDbEventStore;
5
use Nwidart\LaravelBroadway\EventStore\Driver;
6
use Aws\Credentials\Credentials;
7
8
class DynamoDb implements Driver
9
{
10
    /**
11
     * @var \Illuminate\Config\Repository
12
     */
13
    private $config;
14
15
    public function __construct()
16
    {
17
        $this->config = app(\Illuminate\Config\Repository::class);
18
    }
19
20
    /**
21
     * @return object
22
     */
23
    public function getDriver()
24
    {
25
        $payloadSerializer = app(\Broadway\Serializer\Serializer::class);
26
        $metadataSerializer = app(\Broadway\Serializer\Serializer::class);
27
28
        $table = $this->config->get('broadway.event-store.table', 'event_store');
29
        $endpoint =  $this->config->get('broadway.event-store.endpoint', '');
30
        $accessKeyId =  $this->config->get('broadway.event-store.access_key_id', '');
31
        $secretAccessKey =  $this->config->get('broadway.event-store.secret_access_key', '');
32
        $region =  $this->config->get('broadway.event-store.region', '');
33
34
        $credentials = new Credentials($accessKeyId, $secretAccessKey);
35
        $dynamoDbClient = DynamoDbClient::factory([
36
            'region' => $region,
37
            'credentials' => $credentials,
38
            'version' => 'latest',
39
            'endpoint' => $endpoint
40
        ]);
41
42
        $app = app();
43
        $app->singleton(\Aws\DynamoDb\DynamoDbClient::class, function () use ($dynamoDbClient) {
44
            return $dynamoDbClient;
45
        });
46
47
        return new DynamoDbEventStore($dynamoDbClient, $payloadSerializer, $metadataSerializer, $table);
48
    }
49
}
50