diff --git a/src/Factory.php b/src/Factory.php index dbfb2382..9aaad0e1 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -157,31 +157,31 @@ public function createInput($inputSpecification) } break; case 'filters': - if (!is_array($value) && !$value instanceof Traversable && !$value instanceof FilterChain) { + if ($value instanceof FilterChain) { + $input->setFilterChain($value); + break; + } + if (!is_array($value) && !$value instanceof Traversable) { throw new Exception\RuntimeException(sprintf( '%s expects the value associated with "filters" to be an array/Traversable of filters or filter specifications, or a FilterChain; received "%s"', __METHOD__, (is_object($value) ? get_class($value) : gettype($value)) )); } - if ($value instanceof FilterChain) { - $input->setFilterChain($value); - break; - } $this->populateFilters($input->getFilterChain(), $value); break; case 'validators': - if (!is_array($value) && !$value instanceof Traversable && !$value instanceof ValidatorChain) { + if ($value instanceof ValidatorChain) { + $input->setValidatorChain($value); + break; + } + if (!is_array($value) && !$value instanceof Traversable) { throw new Exception\RuntimeException(sprintf( '%s expects the value associated with "validators" to be an array/Traversable of validators or validator specifications, or a ValidatorChain; received "%s"', __METHOD__, (is_object($value) ? get_class($value) : gettype($value)) )); } - if ($value instanceof ValidatorChain) { - $input->setValidatorChain($value); - break; - } $this->populateValidators($input->getValidatorChain(), $value); break; default: diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 0f4cada3..50d82c7c 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -359,4 +359,30 @@ public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecifie $this->assertTrue($inputFilter->has('foo')); $this->assertInstanceOf('Zend\InputFilter\Input', $inputFilter->get('foo')); } + + public function testFactoryAllowsPassingValidatorChainsInInputSpec() + { + $factory = new Factory(); + $chain = new Validator\ValidatorChain(); + $input = $factory->createInput(array( + 'name' => 'foo', + 'validators' => $chain, + )); + $this->assertInstanceOf('Zend\InputFilter\InputInterface', $input); + $test = $input->getValidatorChain(); + $this->assertSame($chain, $test); + } + + public function testFactoryAllowsPassingFilterChainsInInputSpec() + { + $factory = new Factory(); + $chain = new Filter\FilterChain(); + $input = $factory->createInput(array( + 'name' => 'foo', + 'filters' => $chain, + )); + $this->assertInstanceOf('Zend\InputFilter\InputInterface', $input); + $test = $input->getFilterChain(); + $this->assertSame($chain, $test); + } }