Created
February 25, 2015 12:11
-
-
Save mkroeders/aa746a9bff9dc4fcdab3 to your computer and use it in GitHub Desktop.
ZF2 non required input filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\InputFilter; | |
use Zend\InputFilter as ZFI; | |
class InputFilter extends ZFI\InputFilter | |
{ | |
private $required = true; | |
/** | |
* @return boolean | |
*/ | |
public function isRequired() | |
{ | |
return $this->required; | |
} | |
/** | |
* @param boolean $required | |
* | |
* @return $this | |
*/ | |
public function setRequired($required) | |
{ | |
$this->required = (bool) $required; | |
return $this; | |
} | |
/** | |
* @return bool | |
*/ | |
public function isValid() | |
{ | |
if (!$this->isRequired() && empty(array_filter($this->getRawValues()))) { | |
return true; | |
} | |
return parent::isValid(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment