Skip to content

Commit 675316a

Browse files
committed
Allowed values are not optionals
1 parent a7b3637 commit 675316a

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
[![version](https://img.shields.io/badge/version-1.0.0-green.svg)](https://github.com/steevanb/symfony-options-resolver/tree/1.0.0)
1+
[![version](https://img.shields.io/badge/version-1.0.1-green.svg)](https://github.com/steevanb/symfony-options-resolver/tree/1.0.1)
22
[![doctrine](https://img.shields.io/badge/symfony/options_resolver-^2.6||^3.0||^4.0-blue.svg)](https://github.com/symfony/options-resolver)
33
[![php](https://img.shields.io/badge/php-^7.1-blue.svg)](http://www.php.net)
4-
![Lines](https://img.shields.io/badge/code%20lines-369-green.svg)
4+
![Lines](https://img.shields.io/badge/code%20lines-376-green.svg)
55
![Total Downloads](https://poser.pugx.org/steevanb/symfony-options-resolver/downloads)
66
[![Scrutinizer](https://scrutinizer-ci.com/g/steevanb/symfony-options-resolver/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/steevanb/symfony-options-resolver/)
77

@@ -14,7 +14,7 @@ Add features to Symfony [OptionsResolver](https://github.com/symfony/options-res
1414
### Installation
1515

1616
```bash
17-
composer require "steevanb/symfony-options-resolver": "^1.0"
17+
composer require "steevanb/symfony-options-resolver": "^1.0.1"
1818
```
1919

2020
### Examples

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### [1.0.1](../../compare/1.0.0...1.0.1) - 2017-09-30
2+
3+
- `$allowedValues` parameter of `OptionsResolver::confogureOptions()` and `OptionsResolver::configureRequiredOptions()` is now optional.
4+
- [BC BREAK (should not impact a lot of people since library is not downloaded for now)] Inverse `OptionsResolver::configureOptions()` `$default` and `$allowedValues` parameters order.
5+
16
### 1.0.0 - 2019-09-27
27

38
- Create `steevanb\SymfonyOptionsResolver\OptionsResolver`.

src/OptionsResolver.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class OptionsResolver extends SymfonyOptionsResolver
1010
{
11-
public function configureOption(string $name, array $allowedTypes, array $allowedValues, $default): self
11+
public function configureOption(string $name, array $allowedTypes, $default, array $allowedValues = null): self
1212
{
1313
$this
1414
->setAllowedTypesAndValues($name, $allowedTypes, $allowedValues)
@@ -17,7 +17,7 @@ public function configureOption(string $name, array $allowedTypes, array $allowe
1717
return $this;
1818
}
1919

20-
public function configureRequiredOption(string $name, array $allowedTypes, array $allowedValues): self
20+
public function configureRequiredOption(string $name, array $allowedTypes, array $allowedValues = null): self
2121
{
2222
$this
2323
->setAllowedTypesAndValues($name, $allowedTypes, $allowedValues)
@@ -26,12 +26,14 @@ public function configureRequiredOption(string $name, array $allowedTypes, array
2626
return $this;
2727
}
2828

29-
protected function setAllowedTypesAndValues(string $name, array $allowedTypes, array $allowedValues): self
29+
protected function setAllowedTypesAndValues(string $name, array $allowedTypes, array $allowedValues = null): self
3030
{
3131
$this
3232
->setDefined($name)
33-
->setAllowedTypes($name, $allowedTypes)
34-
->setAllowedValues($name, $allowedValues);
33+
->setAllowedTypes($name, $allowedTypes);
34+
if (is_array($allowedValues)) {
35+
$this->setAllowedValues($name, $allowedValues);
36+
}
3537

3638
return $this;
3739
}

tests/OptionsResolverConfigureOptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public function testDefaultValue(): void
4646
private function createOptionsResolver(string $defaultValue = null): OptionsResolver
4747
{
4848
return (new OptionsResolver())
49-
->configureOption('foo', ['string'], ['bar'], $defaultValue);
49+
->configureOption('foo', ['string'], $defaultValue, ['bar']);
5050
}
5151
}

0 commit comments

Comments
 (0)