1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Crummy\Phlack\Common; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver as BaseOptionsResolver; |
6
|
|
|
|
7
|
|
|
class OptionsResolver extends BaseOptionsResolver |
8
|
|
|
{ |
9
|
|
|
private $isLatestVersion; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Set a list of allowed types for the given option. |
13
|
|
|
* |
14
|
|
|
* @see Symfony\Component\OptionsResolver\OptionsResolver::setAllowedTypes() |
15
|
|
|
* |
16
|
|
|
* @param array $allowedTypes |
17
|
|
|
* |
18
|
|
|
* @return $this |
19
|
|
|
*/ |
20
|
30 |
|
public function setTypesAllowed($allowedTypes = null) |
21
|
|
|
{ |
22
|
30 |
|
if (!$this->isLatest()) { |
23
|
|
|
return $this->setAllowedTypes($allowedTypes); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
30 |
|
foreach ($allowedTypes as $option => $typesAllowed) { |
|
|
|
|
27
|
30 |
|
$this->setAllowedTypes($option, $typesAllowed); |
28
|
30 |
|
} |
29
|
|
|
|
30
|
30 |
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
75 |
|
public function setDefined($optionNames) |
37
|
|
|
{ |
38
|
75 |
|
if (!$this->isLatest()) { |
39
|
|
|
return $this->setOptional($optionNames); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
75 |
|
return parent::setDefined($optionNames); |
43
|
|
|
} |
44
|
|
|
|
45
|
22 |
|
public function setNormalizers(array $normalizers) |
46
|
|
|
{ |
47
|
22 |
|
if (!$this->isLatest()) { |
48
|
|
|
return parent::setNormalizers($normalizers); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
22 |
|
foreach ($normalizers as $option => $normalizer) { |
52
|
22 |
|
parent::setNormalizer($option, $normalizer); |
|
|
|
|
53
|
22 |
|
} |
54
|
|
|
|
55
|
22 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Checks whether or not the OptionsResolver version is up-to-date. |
60
|
|
|
* |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
76 |
|
private function isLatest() |
64
|
|
|
{ |
65
|
76 |
|
if (null === $this->isLatestVersion) { |
66
|
76 |
|
$this->isLatestVersion = method_exists(current(class_parents($this)), 'setDefined'); |
67
|
76 |
|
} |
68
|
|
|
|
69
|
76 |
|
return $this->isLatestVersion; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This check looks for function calls that miss required arguments.