forked from prooph/event-store-symfony-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectionManagerFactory.php
61 lines (51 loc) · 2.26 KB
/
ProjectionManagerFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* prooph (http://getprooph.org/)
*
* @see https://github.com/prooph/event-store-symfony-bundle for the canonical source repository
* @copyright Copyright (c) 2016 prooph software GmbH (http://prooph-software.com/)
* @license https://github.com/prooph/event-store-symfony-bundle/blob/master/LICENSE.md New BSD License
*/
declare(strict_types=1);
namespace Prooph\Bundle\EventStore;
use PDO;
use Prooph\Bundle\EventStore\Exception\RuntimeException;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\InMemoryEventStore;
use Prooph\EventStore\Pdo\MariaDbEventStore;
use Prooph\EventStore\Pdo\MySqlEventStore;
use Prooph\EventStore\Pdo\PostgresEventStore;
use Prooph\EventStore\Pdo\Projection\MariaDbProjectionManager;
use Prooph\EventStore\Pdo\Projection\MySqlProjectionManager;
use Prooph\EventStore\Pdo\Projection\PostgresProjectionManager;
use Prooph\EventStore\Projection\InMemoryProjectionManager;
use Prooph\EventStore\Projection\ProjectionManager;
class ProjectionManagerFactory
{
public function createProjectionManager(
EventStore $eventStore,
?PDO $connection = null,
string $eventStreamsTable = 'event_streams',
string $projectionsTable = 'projections'
): ProjectionManager {
$checkConnection = function () use ($connection): PDO {
if (! $connection instanceof PDO) {
throw new RuntimeException('PDO connection missing');
}
return $connection;
};
if ($eventStore instanceof InMemoryEventStore) {
return new InMemoryProjectionManager($eventStore);
}
if ($eventStore instanceof PostgresEventStore) {
return new PostgresProjectionManager($eventStore, $checkConnection(), $eventStreamsTable, $projectionsTable);
}
if ($eventStore instanceof MySqlEventStore) {
return new MySqlProjectionManager($eventStore, $checkConnection(), $eventStreamsTable, $projectionsTable);
}
if ($eventStore instanceof MariaDbEventStore) {
return new MariaDbProjectionManager($eventStore, $checkConnection(), $eventStreamsTable, $projectionsTable);
}
throw new RuntimeException(\sprintf('ProjectionManager for %s not implemented.', \get_class($eventStore)));
}
}