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 hotfix/translator-caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function add($input, $name = null)
* Retrieve a named input
*
* @param string $name
* @throws Exception\InvalidArgumentException
* @return InputInterface|InputFilterInterface
*/
public function get($name)
Expand Down Expand Up @@ -119,6 +120,7 @@ public function remove($name)
* Set data to use when validating and filtering
*
* @param array|Traversable $data
* @throws Exception\InvalidArgumentException
* @return InputFilterInterface
*/
public function setData($data)
Expand All @@ -141,6 +143,7 @@ public function setData($data)
/**
* Is the data set valid?
*
* @throws Exception\RuntimeException
* @return bool
*/
public function isValid()
Expand Down Expand Up @@ -286,6 +289,7 @@ public function getValidInput()
* Retrieve a value from a named input
*
* @param string $name
* @throws Exception\InvalidArgumentException
* @return mixed
*/
public function getValue($name)
Expand Down Expand Up @@ -329,6 +333,7 @@ public function getValues()
* Retrieve a raw (unfiltered) value from a named input
*
* @param string $name
* @throws Exception\InvalidArgumentException
* @return mixed
*/
public function getRawValue($name)
Expand Down
18 changes: 14 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function clearDefaultValidatorChain()
* Factory for input objects
*
* @param array|Traversable $inputSpecification
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
* @return InputInterface|InputFilterInterface
*/
public function createInput($inputSpecification)
Expand Down Expand Up @@ -197,6 +199,8 @@ public function createInput($inputSpecification)
* Factory for input filters
*
* @param array|Traversable $inputFilterSpecification
* @throws Exception\InvalidArgumentException
* @throws Exception\RuntimeException
* @return InputFilterInterface
*/
public function createInputFilter($inputFilterSpecification)
Expand Down Expand Up @@ -228,13 +232,19 @@ public function createInputFilter($inputFilterSpecification)
if (!$inputFilter instanceof InputFilterInterface) {
throw new Exception\RuntimeException(sprintf(
'InputFilter factory expects the "type" to be a class implementing %s; received "%s"',
'Zend\InputFilter\InputFilterInterface',
$class
));
'Zend\InputFilter\InputFilterInterface', $class));
}

foreach ($inputFilterSpecification as $key => $value) {
$input = $this->createInput($value);

if (($value instanceof InputInterface)
|| ($value instanceof InputFilterInterface)
) {
$input = $value;
} else {
$input = $this->createInput($value);
}

$inputFilter->add($input, $key);
}

Expand Down
3 changes: 2 additions & 1 deletion src/InputFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\InputFilter;

use Countable;
use Traversable;

/**
* @category Zend
Expand All @@ -23,7 +24,7 @@ interface InputFilterInterface extends Countable
/**
* Add an input to the input filter
*
* @param InputInterface|InputFilterInterface $input
* @param InputInterface|InputFilterInterface|array $input
* @param null|string $name Name used to retrieve this input
* @return InputFilterInterface
*/
Expand Down
28 changes: 28 additions & 0 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,34 @@ public function testFactoryWillCreateInputWithSuggestedName()
$this->assertEquals('foo', $input->getName());
}

public function testFactoryAcceptsInputInterface()
{
$factory = new Factory();
$input = new Input();

$inputFilter = $factory->createInputFilter(array(
'foo' => $input
));

$this->assertInstanceOf('Zend\InputFilter\InputFilterInterface', $inputFilter);
$this->assertTrue($inputFilter->has('foo'));
$this->assertTrue($inputFilter->get('foo') === $input);
}

public function testFactoryAcceptsInputFilterInterface()
{
$factory = new Factory();
$input = new InputFilter();

$inputFilter = $factory->createInputFilter(array(
'foo' => $input
));

$this->assertInstanceOf('Zend\InputFilter\InputFilterInterface', $inputFilter);
$this->assertTrue($inputFilter->has('foo'));
$this->assertTrue($inputFilter->get('foo') === $input);
}

public function testFactoryWillCreateInputFilterAndAllInputObjectsFromGivenConfiguration()
{
$factory = new Factory();
Expand Down

0 comments on commit 3e0855f

Please sign in to comment.