1 | <?php |
||
20 | * Use this exception if an option was not found in the config |
||
21 | */ |
||
22 | class OptionNotFoundException extends OutOfBoundsException |
||
23 | { |
||
24 | /** |
||
25 | * @param RequiresConfig $factory |
||
26 | * @param mixed $currentDimension Current configuration key |
||
27 | * @param string $configId |
||
28 | * @return OptionNotFoundException |
||
29 | */ |
||
30 | 6 | public static function missingOptions(RequiresConfig $factory, $currentDimension, ?string $configId) : self |
|
|
|||
31 | { |
||
32 | 6 | $position = []; |
|
33 | |||
34 | 6 | $dimensions = $factory->dimensions(); |
|
35 | |||
36 | 6 | if ($factory instanceof RequiresConfigId) { |
|
37 | 3 | $dimensions[] = $configId; |
|
38 | } |
||
39 | |||
40 | 6 | foreach ($dimensions as $dimension) { |
|
41 | 6 | $position[] = $dimension; |
|
42 | |||
43 | 6 | if ($dimension === $currentDimension) { |
|
44 | 6 | break; |
|
45 | } |
||
46 | } |
||
47 | |||
48 | 6 | if ($factory instanceof RequiresConfigId && $configId === null && count($dimensions) === count($position)) { |
|
49 | 2 | return new static( |
|
50 | rtrim( |
||
51 | 2 | sprintf('The configuration "%s" needs a config id.', implode('.', $position)), |
|
52 | 2 | '.' |
|
53 | ) |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | 4 | return new static(sprintf('No options set for configuration "%s"', implode('.', $position))); |
|
58 | } |
||
60 |