Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e44405

Browse filesBrowse files
committed
fixed comments
1 parent e2ce878 commit 3e44405
Copy full SHA for 3e44405

File tree

3 files changed

+37
-27
lines changed
Filter options

3 files changed

+37
-27
lines changed

‎src/Symfony/Component/OptionsResolver/OptionConfigurator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionConfigurator.php
+25-17Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
final class OptionConfigurator
1717
{
1818
private $name;
19-
2019
private $resolver;
2120

2221
public function __construct(string $name, OptionsResolver $resolver)
@@ -29,13 +28,13 @@ public function __construct(string $name, OptionsResolver $resolver)
2928
/**
3029
* Adds allowed values for this option.
3130
*
32-
* @param mixed $allowedValues One or more acceptable values/closures
31+
* @param mixed ...$allowedValues One or more acceptable values/closures
3332
*
3433
* @return $this
3534
*
3635
* @throws AccessException If called from a lazy option or normalizer
3736
*/
38-
public function addAllowedValues($allowedValues): self
37+
public function addAllowedValues(...$allowedValues): self
3938
{
4039
$this->resolver->addAllowedValues($this->name, $allowedValues);
4140

@@ -45,13 +44,13 @@ public function addAllowedValues($allowedValues): self
4544
/**
4645
* Sets allowed types for this option.
4746
*
48-
* @param string|string[] $allowedTypes One or more accepted types
47+
* @param string ...$allowedTypes One or more accepted types
4948
*
5049
* @return $this
5150
*
5251
* @throws AccessException If called from a lazy option or normalizer
5352
*/
54-
public function addAllowedTypes($allowedTypes): self
53+
public function addAllowedTypes(string ...$allowedTypes): self
5554
{
5655
$this->resolver->addAllowedTypes($this->name, $allowedTypes);
5756

@@ -61,32 +60,43 @@ public function addAllowedTypes($allowedTypes): self
6160
/**
6261
* Adds a normalizer for this option.
6362
*
64-
* @param \Closure $normalizer The normalizer
65-
* @param bool $forcePrepend If set to true, prepend instead of appending
63+
* @return $this
64+
*
65+
* @throws AccessException If called from a lazy option or normalizer
66+
*/
67+
public function addNormalizer(\Closure $normalizer): self
68+
{
69+
$this->resolver->addNormalizer($this->name, $normalizer);
70+
71+
return $this;
72+
}
73+
74+
/**
75+
* Prepends a normalizer for this option.
6676
*
6777
* @return $this
6878
*
6979
* @throws AccessException If called from a lazy option or normalizer
7080
*/
71-
public function addNormalizer(\Closure $normalizer, bool $forcePrepend = false): self
81+
public function prependNormalizer(\Closure $normalizer): self
7282
{
73-
$this->resolver->addNormalizer($this->name, $normalizer, $forcePrepend);
83+
$this->resolver->addNormalizer($this->name, $normalizer, true);
7484

7585
return $this;
7686
}
7787

7888
/**
7989
* Adds allowed types for this option.
8090
*
81-
* @param string|string[] $types One or more accepted types
91+
* @param string ...$types One or more accepted types
8292
*
8393
* @return $this
8494
*
8595
* @throws AccessException If called from a lazy option or normalizer
8696
*/
87-
public function allowedTypes($types): self
97+
public function allowedTypes(string ...$types): self
8898
{
89-
$this->resolver->addAllowedTypes($this->name, $types);
99+
$this->resolver->setAllowedTypes($this->name, $types);
90100

91101
return $this;
92102
}
@@ -100,7 +110,7 @@ public function allowedTypes($types): self
100110
*
101111
* @throws AccessException If called from a lazy option or normalizer
102112
*/
103-
public function allowedValues($values): self
113+
public function allowedValues(...$values): self
104114
{
105115
$this->resolver->setAllowedValues($this->name, $values);
106116

@@ -125,12 +135,10 @@ public function default($value): self
125135

126136
/**
127137
* Defines an option configurator with the given name.
128-
*
129-
* @param string $optionName The option name
130138
*/
131-
public function define(string $optionName): self
139+
public function define(string $option): self
132140
{
133-
return $this->resolver->define($optionName);
141+
return $this->resolver->define($option);
134142
}
135143

136144
/**

‎src/Symfony/Component/OptionsResolver/OptionsResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionsResolver.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,10 @@ public function addAllowedTypes($option, $allowedTypes)
705705

706706
/**
707707
* Defines an option configurator with the given name.
708-
*
709-
* @param string $optionName The option name
710708
*/
711-
public function define(string $optionName): OptionConfigurator
709+
public function define(string $option): OptionConfigurator
712710
{
713-
return new OptionConfigurator($optionName, $this);
711+
return new OptionConfigurator($option, $this);
714712
}
715713

716714
/**

‎src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,24 +2381,28 @@ public function testResolveOptionsDefinedByOptionConfigurator()
23812381
->required()
23822382
->deprecated()
23832383
->default('bar')
2384-
->allowedTypes('string')
2384+
->allowedTypes('string', 'bool')
23852385
->addAllowedTypes('null')
2386-
->allowedValues('bar')
2386+
->allowedValues('bar', 'zab')
23872387
->addAllowedValues('baz')
23882388
->normalize(static function (Options $options, $value) {
23892389
return $value;
23902390
})
23912391
->addNormalizer(static function (Options $options, $value) {
23922392
return $value;
2393-
}, true);
2393+
})
2394+
->prependNormalizer(static function (Options $options, $value) {
2395+
return $value;
2396+
})
2397+
;
23942398
$introspector = new OptionsResolverIntrospector($this->resolver);
23952399

23962400
$this->assertTrue(true, $this->resolver->isDefined('foo'));
23972401
$this->assertTrue(true, $this->resolver->isDeprecated('foo'));
23982402
$this->assertTrue(true, $this->resolver->hasDefault('foo'));
23992403
$this->assertSame('bar', $introspector->getDefault('foo'));
2400-
$this->assertSame(['string', 'null'], $introspector->getAllowedTypes('foo'));
2401-
$this->assertSame(['bar', 'baz'], $introspector->getAllowedValues('foo'));
2402-
$this->assertCount(2, $introspector->getNormalizers('foo'));
2404+
$this->assertSame(['string', 'bool', 'null'], $introspector->getAllowedTypes('foo'));
2405+
$this->assertSame(['bar', 'zab', 'baz'], $introspector->getAllowedValues('foo'));
2406+
$this->assertCount(3, $introspector->getNormalizers('foo'));
24032407
}
24042408
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.