diff --git a/src/BaseInputFilter.php b/src/BaseInputFilter.php index 8d8f1f45..1d0f17d9 100644 --- a/src/BaseInputFilter.php +++ b/src/BaseInputFilter.php @@ -103,6 +103,18 @@ public function has($name) return (array_key_exists($name, $this->inputs)); } + /** + * Remove a named input + * + * @param string $name + * @return InputFilterInterface + */ + public function remove($name) + { + unset($this->inputs[$name]); + return $this; + } + /** * Set data to use when validating and filtering * diff --git a/src/InputFilterInterface.php b/src/InputFilterInterface.php index 089ba203..e413bb53 100644 --- a/src/InputFilterInterface.php +++ b/src/InputFilterInterface.php @@ -45,6 +45,14 @@ public function get($name); */ public function has($name); + /** + * Remove a named input + * + * @param string $name + * @return InputFilterInterface + */ + public function remove($name); + /** * Set data to use when validating and filtering * diff --git a/test/BaseInputFilterTest.php b/test/BaseInputFilterTest.php index 5dec9f4c..2187e9e0 100644 --- a/test/BaseInputFilterTest.php +++ b/test/BaseInputFilterTest.php @@ -55,6 +55,17 @@ public function testCanAddInputFilterAsInput() $this->assertSame($child, $parent->get('child')); } + public function testCanRemoveInputFilter() + { + $parent = new InputFilter(); + $child = new InputFilter(); + $parent->add($child, 'child'); + $this->assertEquals(1, count($parent)); + $this->assertSame($child, $parent->get('child')); + $parent->remove('child'); + $this->assertEquals(0, count($parent)); + } + public function getInputFilter() { $filter = new InputFilter();