File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,23 @@ public function setParameter($name, $value)
191191 $ this ->config [$ name ] = $ value ;
192192 }
193193
194+ public function mergeParameter ($ name , array $ values )
195+ {
196+ $ actual = $ this ->getParameter ($ name );
197+
198+ if (!is_array ($ actual )) {
199+ throw new \InvalidArgumentException (sprintf (
200+ 'Cannot merge values on to a scalar parameter "%s" ' ,
201+ $ name
202+ ));
203+ }
204+
205+ $ this ->setParameter ($ name , array_merge (
206+ $ actual ,
207+ $ values
208+ ));
209+ }
210+
194211 /**
195212 * Return the parameter with the given name.
196213 *
Original file line number Diff line number Diff line change @@ -130,6 +130,32 @@ public function testRegisterExtensionWithUserConfig()
130130 $ this ->assertEquals ('bazz ' , $ object ->foobar );
131131 }
132132
133+ /**
134+ * It should merge parameters.
135+ */
136+ public function testMergeParameters ()
137+ {
138+ $ this ->container ->setParameter ('foo ' , [ 'foo ' => 'bar ' ]);
139+ $ this ->container ->mergeParameter ('foo ' , [ 'bar ' => 'boo ' ]);
140+ $ this ->assertEquals ([
141+ 'foo ' => 'bar ' ,
142+ 'bar ' => 'boo '
143+ ], $ this ->container ->getParameter ('foo ' ));
144+ }
145+
146+ /**
147+ * It should throw an exception when trying to merge a value into a non-array parameter.
148+ *
149+ * @expectedException \InvalidArgumentException
150+ * @expectedExceptionMessage scalar
151+ */
152+ public function testMergeParameterNonArray ()
153+ {
154+ $ this ->container ->setParameter ('foo ' , 'bar ' );
155+ $ this ->container ->mergeParameter ('foo ' , [ 'bar ' => 'boo ' ]);
156+ }
157+
158+
133159 /**
134160 * It should throw an exception if an extension class does not exist.
135161 *
You can’t perform that action at this time.
0 commit comments