|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Pheature\Crud\Psr11\Toggle; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
use Pheature\Core\Toggle\Read\FeatureFinder; |
|
10
|
|
|
use Pheature\Dbal\Toggle\Read\DbalFeatureFactory; |
|
11
|
|
|
use Pheature\Dbal\Toggle\Read\DbalFeatureFinder; |
|
12
|
|
|
use Pheature\InMemory\Toggle\InMemoryConfig; |
|
13
|
|
|
use Pheature\InMemory\Toggle\InMemoryFeatureFactory; |
|
14
|
|
|
use Pheature\InMemory\Toggle\InMemoryFeatureFinder; |
|
15
|
|
|
use Psr\Container\ContainerInterface; |
|
16
|
|
|
|
|
17
|
|
|
final class FeatureFinderFactory |
|
18
|
|
|
{ |
|
19
|
3 |
|
public function __invoke(ContainerInterface $container): FeatureFinder |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var ToggleConfig $config */ |
|
22
|
3 |
|
$config = $container->get(ToggleConfig::class); |
|
23
|
|
|
/** @var ?Connection $connection */ |
|
24
|
3 |
|
$connection = $container->get(Connection::class); |
|
25
|
|
|
|
|
26
|
3 |
|
return self::create($config, $connection); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
5 |
|
public static function create(ToggleConfig $config, ?Connection $connection): FeatureFinder |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
5 |
|
$driver = $config->driver(); |
|
33
|
|
|
|
|
34
|
5 |
|
if ('inmemory' === $driver) { |
|
35
|
2 |
|
return new InMemoryFeatureFinder( |
|
36
|
2 |
|
new InMemoryConfig($config->toggles()), |
|
37
|
2 |
|
new InMemoryFeatureFactory() |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
3 |
|
if ('dbal' === $driver) { |
|
42
|
|
|
/** @var Connection $connection */ |
|
43
|
2 |
|
return new DbalFeatureFinder($connection, new DbalFeatureFactory()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
throw new InvalidArgumentException('Valid driver required'); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|