[OptionsResolver] Optimized previous values of a lazy option not to be evaluated if the second argument is not defined

This commit is contained in:
Bernhard Schussek 2012-07-26 15:35:08 +02:00
parent 8a338cb6fa
commit d858f7bdf3
2 changed files with 18 additions and 1 deletions

View File

@ -190,7 +190,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable
$params = $reflClosure->getParameters();
if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && __CLASS__ === $class->name) {
$currentValue = isset($this->options[$option]) ? $this->options[$option] : null;
$currentValue = isset($params[1]) && isset($this->options[$option]) ? $this->options[$option] : null;
$value = new LazyOption($value, $currentValue);
// Store which options are lazy for more efficient resolving

View File

@ -156,6 +156,23 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('dynamic', $this->options->get('foo'));
}
public function testPreviousValueIsNotEvaluatedIfNoSecondArgument()
{
$test = $this;
// defined by superclass
$this->options->set('foo', function (Options $options) use ($test) {
$test->fail('Should not be called');
});
// defined by subclass, no $previousValue argument defined!
$this->options->overload('foo', function (Options $options) use ($test) {
return 'dynamic';
});
$this->assertEquals('dynamic', $this->options->get('foo'));
}
public function testLazyOptionCanAccessOtherOptions()
{
$test = $this;