Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into form/select-date
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function add($input, $name = null)
));
}

if (is_null($name) || $name === '') {
if ($input instanceof InputInterface && (empty($name) || is_int($name))) {
$name = $input->getName();
}

Expand Down
14 changes: 11 additions & 3 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,27 @@ public function createInput($inputSpecification)
}
break;
case 'filters':
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; received "%s"',
'%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))
));
}
$this->populateFilters($input->getFilterChain(), $value);
break;
case 'validators':
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; received "%s"',
'%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))
));
Expand Down Expand Up @@ -205,7 +213,7 @@ public function createInputFilter($inputFilterSpecification)
}

$class = 'Zend\InputFilter\InputFilter';
if (isset($inputFilterSpecification['type'])) {
if (isset($inputFilterSpecification['type']) && is_string($inputFilterSpecification['type'])) {
$class = $inputFilterSpecification['type'];
if (!class_exists($class)) {
throw new Exception\RuntimeException(sprintf(
Expand Down
37 changes: 37 additions & 0 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,41 @@ public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfi
}
}
}

public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecified()
{
$factory = new Factory();
$inputFilter = $factory->createInputFilter(array(
array('name' => 'foo')
));

$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);
}
}

0 comments on commit 3951384

Please sign in to comment.