Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e322748

Browse files
committed
[OptionsResolver] Merged Options and OptionsConfig and restored old OptionsResolver class
1 parent 966c586 commit e322748

File tree

8 files changed

+1919
-1042
lines changed

8 files changed

+1919
-1042
lines changed

UPGRADE-2.6.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,67 @@ HttpFoundation
128128
- You would need to migrate the table manually if you want to keep session information of your users.
129129
- You could use `PdoSessionHandler::createTable` to initialize a correctly defined table depending on
130130
the used database vendor.
131+
132+
OptionsResolver
133+
---------------
134+
135+
* The class `OptionsResolver` and its interface `OptionsResolverInterface`
136+
were deprecated. You should use the class `Options` together with
137+
`Options::resolve()` instead.
138+
139+
In simple use cases, you don't need to instantiate a class anymore:
140+
141+
Before:
142+
143+
```php
144+
$resolver = new OptionsResolver();
145+
$resolver->setDefaults(array(
146+
'username' => 'user',
147+
'password' => 'pa$$word',
148+
'port' => 25,
149+
));
150+
$resolver->setRequired(array('host'));
151+
$resolver->setAllowedTypes(array(
152+
'port' => 'int',
153+
));
154+
155+
$options = $resolver->resolve($options);
156+
```
157+
158+
After:
159+
160+
```php
161+
Options::validateRequired($options, 'host')
162+
Options::validateTypes($options, array(
163+
'port' => 'int',
164+
));
165+
166+
$options = Options::resolve($options, array(
167+
'username' => 'user',
168+
'password' => 'pa$$word',
169+
'port' => 25,
170+
));
171+
```
172+
173+
When you want to distribute the configuration of the options and pass a
174+
configuration object around, construct a new `Options` instance. The API
175+
of that class is very similar to the `OptionsResolver`. Additionally, you
176+
can use its `ArrayAccess` interface to set default option values:
177+
178+
```php
179+
// Pass options to the constructor...
180+
$defaults = new Options(array(
181+
'username' => 'user',
182+
'password' => 'pa$$word',
183+
));
184+
185+
// ...or using array access
186+
$defaults['port'] = 25;
187+
188+
$defaults->setRequired('host');
189+
$defaults->setAllowedTypes(array(
190+
'port' => 'int',
191+
));
192+
193+
$options = Options::resolve($options, $defaults);
194+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CHANGELOG
2+
=========
3+
4+
2.6.0
5+
-----
6+
7+
* added Options::resolve()
8+
* added Options::validateRequired()
9+
* added Options::validateTypes()
10+
* added Options::validateValues()
11+
* deprecated OptionsResolver
12+
* deprecated OptionsResolverInterface

0 commit comments

Comments
 (0)