1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Sandro Keil (https://sandro-keil.de) |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/sandrokeil/interop-config for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2015-2016 Sandro Keil |
7
|
|
|
* @license http://github.com/sandrokeil/interop-config/blob/master/LICENSE.md New BSD License |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Interop\Config\Exception; |
11
|
|
|
|
12
|
|
|
use Interop\Config\RequiresConfig; |
13
|
|
|
use Interop\Config\RequiresConfigId; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Option not found exception |
17
|
|
|
* |
18
|
|
|
* Use this exception if an option was not found in the config |
19
|
|
|
*/ |
20
|
|
|
class OptionNotFoundException extends OutOfBoundsException |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @param RequiresConfig $factory |
24
|
|
|
* @param mixed $currentDimension Current configuration key |
25
|
|
|
* @param string $configId |
26
|
|
|
* @return InvalidArgumentException |
27
|
|
|
*/ |
28
|
5 |
|
public static function missingOptions(RequiresConfig $factory, $currentDimension, $configId) |
29
|
|
|
{ |
30
|
5 |
|
$position = []; |
31
|
|
|
|
32
|
5 |
|
$dimensions = $factory->dimensions(); |
33
|
|
|
|
34
|
5 |
|
if ($factory instanceof RequiresConfigId) { |
35
|
2 |
|
$dimensions[] = $configId; |
36
|
|
|
} |
37
|
|
|
|
38
|
5 |
|
foreach ($dimensions as $dimension) { |
39
|
5 |
|
$position[] = $dimension; |
40
|
|
|
|
41
|
5 |
|
if ($dimension === $currentDimension) { |
42
|
5 |
|
break; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
5 |
|
if ($factory instanceof RequiresConfigId && $configId === null && count($dimensions) === count($position)) { |
47
|
1 |
|
return new static( |
48
|
|
|
rtrim( |
49
|
1 |
|
sprintf('The configuration "%s" needs a config id.', implode('.', $position)), |
50
|
1 |
|
'.' |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
4 |
|
return new static(sprintf('No options set for configuration "%s"', implode('.', $position))); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|