10000 [OptionsResolver] Made the OptionsResolver clonable · sigues/symfony@a924dab · GitHub
[go: up one dir, main page]

Skip to content

Commit a924dab

Browse files
committed
[OptionsResolver] Made the OptionsResolver clonable
1 parent 70307e5 commit a924dab

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public function __construct()
6767
$this->defaultOptions = new Options();
6868
}
6969

70+
/**
71+
* Clones the resolver.
72+
*/
73+
public function __clone()
74+
{
75+
$this->defaultOptions = clone $this->defaultOptions;
76+
}
77+
7078
/**
7179
* {@inheritdoc}
7280
*/
@@ -210,7 +218,7 @@ public function isRequired($option)
210218
/**
211219
* {@inheritdoc}
212220
*/
213-
public function resolve(array $options)
221+
public function resolve(array $options = array())
214222
{
215223
$this->validateOptionsExistence($options);
216224
$this->validateOptionsCompleteness($options);

src/Symfony/Component/OptionsResolver/OptionsResolverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,5 @@ public function isRequired($option);
206206
* @throws Exception\OptionDefinitionException If a cyclic dependency is detected
207207
* between two lazy options.
208208
*/
209-
public function resolve(array $options);
209+
public function resolve(array $options = array());
210210
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,25 @@ public function testResolveSucceedsIfOptionRequiredAndValueAllowed()
612612

613613
$this->assertEquals($options, $this->resolver->resolve($options));
614614
}
615+
616+
public function testClone()
617+
{
618+
$this->resolver->setDefaults(array('one' => '1'));
619+
620+
$clone = clone $this->resolver;
621+
622+
// Changes after cloning don't affect each other
623+
$this->resolver->setDefaults(array('two' => '2'));
624+
$clone->setDefaults(array('three' => '3'));
625+
626+
$this->assertEquals(array(
627+
'one' => '1',
628+
'two' => '2',
629+
), $this->resolver->resolve());
630+
631+
$this->assertEquals(array(
632+
'one' => '1',
633+
'three' => '3',
634+
), $clone->resolve());
635+
}
615636
}

0 commit comments

Comments
 (0)
0