Skip to content

Instantly share code, notes, and snippets.

@mkroeders
Created February 25, 2015 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkroeders/aa746a9bff9dc4fcdab3 to your computer and use it in GitHub Desktop.
Save mkroeders/aa746a9bff9dc4fcdab3 to your computer and use it in GitHub Desktop.
ZF2 non required input filter
<?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