File tree 3 files changed +35
-2
lines changed
src/Symfony/Component/Config
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ CHANGELOG
8
8
* added second ` $exists ` constructor argument to ` ClassExistenceResource `
9
9
* made ` ClassExistenceResource ` work with interfaces and traits
10
10
* added ` ConfigCachePass ` (originally in FrameworkBundle)
11
+ * added ` castToArray() ` helper to turn any config value into an array
11
12
12
13
3.0.0
13
14
-----
@@ -36,7 +37,7 @@ Before: `InvalidArgumentException` (variable must contain at least two
36
37
distinct elements).
37
38
After: the code will work as expected and it will restrict the values of the
38
39
` variable ` option to just ` value ` .
39
-
40
+
40
41
* deprecated the ` ResourceInterface::isFresh() ` method. If you implement custom resource types and they
41
42
can be validated that way, make them implement the new ` SelfCheckingResourceInterface ` .
42
43
* deprecated the getResource() method in ResourceInterface. You can still call this method
@@ -49,7 +50,7 @@ After: the code will work as expected and it will restrict the values of the
49
50
50
51
* added ` ConfigCacheInterface ` , ` ConfigCacheFactoryInterface ` and a basic ` ConfigCacheFactory `
51
52
implementation to delegate creation of ConfigCache instances
52
-
53
+
53
54
2.2.0
54
55
-----
55
56
Original file line number Diff line number Diff line change @@ -149,6 +149,19 @@ public function ifNotInArray(array $array)
149
149
return $ this ;
150
150
}
151
151
152
+ /**
153
+ * Transforms variables of any type into an array.
154
+ *
155
+ * @return $this
156
+ */
157
+ public function castToArray ()
158
+ {
159
+ $ this ->ifPart = function ($ v ) { return !is_array ($ v ); };
160
+ $ this ->thenPart = function ($ v ) { return array ($ v ); };
161
+
162
+ return $ this ;
163
+ }
164
+
152
165
/**
153
166
* Sets the closure to run if the test pass.
154
167
*
Original file line number Diff line number Diff line change @@ -145,6 +145,25 @@ public function testThenEmptyArrayExpression()
145
145
$ this ->assertFinalizedValueIs (array (), $ test );
146
146
}
147
147
148
+ /**
149
+ * @dataProvider castToArrayValues
150
+ */
151
+ public function testcastToArrayExpression ($ configValue , $ expectedValue )
152
+ {
153
+ $ test = $ this ->getTestBuilder ()
154
+ ->castToArray ()
155
+ ->end ();
156
+ $ this ->assertFinalizedValueIs ($ expectedValue , $ test , array ('key ' => $ configValue ));
157
+ }
158
+
159
+ public function castToArrayValues ()
160
+ {
161
+ yield array ('value ' , array ('value ' ));
162
+ yield array (-3.14 , array (-3.14 ));
163
+ yield array (null , array (null ));
164
+ yield array (array ('value ' ), array ('value ' ));
165
+ }
166
+
148
167
/**
149
168
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
150
169
*/
You can’t perform that action at this time.
0 commit comments