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

added method to merge input filters #6431

Closed
wants to merge 10 commits into from
13 changes: 13 additions & 0 deletions library/Zend/InputFilter/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,4 +684,17 @@ public function getInputs()
{
return $this->inputs;
}

/**
* Merges the inputs from an InputFilter into the current one
*
* @param BaseInputFilter $inputFilter
* @return $this
*/
public function merge(BaseInputFilter $inputFilter)
{
foreach ($inputFilter->getInputs() as $name => $input) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the chained input filter is being changed afterwards?

This is more like "Merge" rather than "Chain". In a chain, I'd expect elements to keep interacting together after the chaining has happened: that's not the case here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, in this case the method name as merge will make more sense

On Tue, Aug 5, 2014 at 1:04 PM, Marco Pivetta notifications@github.com
wrote:

In library/Zend/InputFilter/BaseInputFilter.php:

@@ -683,4 +683,18 @@ public function getInputs()
{
return $this->inputs;
}
+

  • /**
  • \* Chain the inputs from an InputFilter into the current one
    
  • *
    
  • \* @param BaseInputFilter $inputFilter
    
  • \* @return $this
    
  • */
    
  • public function chainInputFilter(BaseInputFilter $inputFilter)
  • {
  •    foreach ($inputFilter->getInputs() as $name => $input) {
    

What happens if the chained input filter is being changed afterwards?

This is more like "Merge" rather than "Chain". In a chain, I'd expect
elements to keep interacting together after the chaining has happened:
that's not the case here.


Reply to this email directly or view it on GitHub
https://github.com/zendframework/zf2/pull/6431/files#r15807663.

$this->add($input, $name);
}
}
}
21 changes: 21 additions & 0 deletions tests/ZendTest/InputFilter/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,4 +912,25 @@ public function testPopulateSupportsArrayInputEvenIfDataMissing()
$filter->add($arrayInput, 'arrayInput');
$filter->setData(array('foo' => 'bar'));
}

public function testMerge()
{
$expectedFilters = array(
'foo',
'bar',
'baz'
);

$inputFilter = new InputFilter();
$chainedInputFilter = new InputFilter();

$inputFilter->add(new Input(), 'foo');
$inputFilter->add(new Input(), 'bar');

$chainedInputFilter->add(new Input(), 'baz');

$inputFilter->merge($chainedInputFilter);

$this->assertEquals($expectedFilters, array_keys($inputFilter->getInputs()));
}
}