1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Pheature\Crud\Psr11\Toggle; |
6
|
|
|
|
7
|
|
|
use Webmozart\Assert\Assert; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @psalm-import-type WriteFeature from \Pheature\Core\Toggle\Write\Feature |
11
|
|
|
* @psalm-import-type InMemoryFeature from \Pheature\InMemory\Toggle\InMemoryConfig |
12
|
|
|
* @psalm-type StrategyTypeFactoryConfig array<array{type: string, factory_id: string}> |
13
|
|
|
* @psalm-type SegmentTypeFactoryConfig array<array{type: string, factory_id: string}> |
14
|
|
|
* @psalm-type ToggleConfigOptions array{ |
15
|
|
|
* api_enabled: bool, |
16
|
|
|
* api_prefix: string, |
17
|
|
|
* driver: string, |
18
|
|
|
* driver_options?: array<string>, |
19
|
|
|
* strategy_types?: StrategyTypeFactoryConfig, |
20
|
|
|
* segment_types?: SegmentTypeFactoryConfig, |
21
|
|
|
* toggles?: array<InMemoryFeature> |
22
|
|
|
* } |
23
|
|
|
*/ |
24
|
|
|
final class ToggleConfig |
25
|
|
|
{ |
26
|
|
|
public const DRIVER_IN_MEMORY = 'inmemory'; |
27
|
|
|
public const DRIVER_DBAL = 'dbal'; |
28
|
|
|
public const DRIVER_CHAIN = 'chain'; |
29
|
|
|
private const VALID_DRIVERS = [ |
30
|
|
|
self::DRIVER_IN_MEMORY, |
31
|
|
|
self::DRIVER_DBAL, |
32
|
|
|
self::DRIVER_CHAIN, |
33
|
|
|
]; |
34
|
|
|
private const VALID_DRIVER_OPTIONS = [ |
35
|
|
|
self::DRIVER_IN_MEMORY, |
36
|
|
|
self::DRIVER_DBAL, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
private string $driver; |
40
|
|
|
/** @var array<string> */ |
41
|
|
|
private $driverOptions; |
42
|
|
|
private bool $apiEnabled; |
43
|
|
|
private string $apiPrefix; |
44
|
|
|
/** @var StrategyTypeFactoryConfig */ |
|
|
|
|
45
|
|
|
private array $strategyTypes; |
46
|
|
|
/** @var SegmentTypeFactoryConfig */ |
|
|
|
|
47
|
|
|
private array $segmentTypes; |
48
|
|
|
/** @var array<InMemoryFeature> */ |
49
|
|
|
private array $toggles; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param array<string, mixed> $config |
53
|
|
|
*/ |
54
|
37 |
|
public function __construct(array $config) |
55
|
|
|
{ |
56
|
37 |
|
$this->assertDriver($config); |
57
|
27 |
|
Assert::keyExists($config, 'api_enabled'); |
58
|
26 |
|
Assert::boolean($config['api_enabled']); |
59
|
25 |
|
Assert::keyExists($config, 'api_prefix'); |
60
|
24 |
|
Assert::string($config['api_prefix']); |
61
|
|
|
|
62
|
23 |
|
$this->apiEnabled = $config['api_enabled']; |
63
|
23 |
|
$this->apiPrefix = $config['api_prefix']; |
64
|
|
|
/** @var string $driver */ |
65
|
23 |
|
$driver = $config['driver']; |
66
|
23 |
|
$this->driver = $driver; |
67
|
|
|
/** @var array<string> $driverOptions */ |
68
|
23 |
|
$driverOptions = $config['driver_options'] ?? []; |
69
|
23 |
|
$this->driverOptions = $driverOptions; |
70
|
|
|
|
71
|
23 |
|
$this->strategyTypes = []; |
|
|
|
|
72
|
23 |
|
$this->segmentTypes = []; |
|
|
|
|
73
|
23 |
|
$this->toggles = []; |
74
|
|
|
|
75
|
23 |
|
if (array_key_exists('strategy_types', $config)) { |
76
|
11 |
|
Assert::isArray($config['strategy_types']); |
77
|
|
|
/** @var array<array{type: string, factory_id: string}> $strategyTypes */ |
78
|
10 |
|
$strategyTypes = $config['strategy_types']; |
79
|
10 |
|
$this->strategyTypes = $strategyTypes; |
80
|
|
|
} |
81
|
|
|
|
82
|
22 |
|
if (array_key_exists('segment_types', $config)) { |
83
|
10 |
|
Assert::isArray($config['segment_types']); |
84
|
|
|
/** @var array<array{type: string, factory_id: string}> $segmentTypes */ |
85
|
9 |
|
$segmentTypes = $config['segment_types']; |
86
|
9 |
|
$this->segmentTypes = $segmentTypes; |
87
|
|
|
} |
88
|
|
|
|
89
|
21 |
|
if (array_key_exists('toggles', $config)) { |
90
|
12 |
|
Assert::isArray($config['toggles']); |
91
|
|
|
/** @var array<InMemoryFeature> $toggles */ |
92
|
11 |
|
$toggles = $config['toggles']; |
93
|
11 |
|
$this->toggles = $toggles; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param array<string, mixed> $config |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
37 |
|
private function assertDriver(array $config): void |
102
|
|
|
{ |
103
|
37 |
|
Assert::keyExists($config, 'driver'); |
104
|
35 |
|
Assert::inArray($config['driver'], self::VALID_DRIVERS); |
105
|
|
|
|
106
|
31 |
|
$this->assertDriverOptions($config); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param array<string, mixed> $config |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
31 |
|
private function assertDriverOptions(array $config): void |
114
|
|
|
{ |
115
|
31 |
|
if (self::DRIVER_CHAIN === $config['driver']) { |
116
|
10 |
|
Assert::keyExists($config, 'driver_options'); |
117
|
9 |
|
Assert::notEmpty($config['driver_options']); |
118
|
7 |
|
Assert::allInArray($config['driver_options'], self::VALID_DRIVER_OPTIONS); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
3 |
|
public function apiEnabled(): bool |
123
|
|
|
{ |
124
|
3 |
|
return $this->apiEnabled; |
125
|
|
|
} |
126
|
|
|
|
127
|
3 |
|
public function apiPrefix(): string |
128
|
|
|
{ |
129
|
3 |
|
return $this->apiPrefix; |
130
|
|
|
} |
131
|
|
|
|
132
|
17 |
|
public function driver(): string |
133
|
|
|
{ |
134
|
17 |
|
return $this->driver; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return array<string> |
139
|
|
|
*/ |
140
|
9 |
|
public function driverOptions(): array |
141
|
|
|
{ |
142
|
9 |
|
return $this->driverOptions; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** @return StrategyTypeFactoryConfig */ |
146
|
1 |
|
public function strategyTypes(): array |
147
|
|
|
{ |
148
|
1 |
|
return $this->strategyTypes; |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** @return SegmentTypeFactoryConfig */ |
152
|
|
|
public function segmentTypes(): array |
153
|
|
|
{ |
154
|
|
|
return $this->segmentTypes; |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** @return array<InMemoryFeature> */ |
158
|
5 |
|
public function toggles(): array |
159
|
|
|
{ |
160
|
5 |
|
return $this->toggles; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths