Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace User\Entity;
- use Zend\InputFilter\Factory as InputFactory;
- use Zend\InputFilter\InputFilter;
- use Zend\InputFilter\InputFilterInterface;
- use Zend\Db\Adapter\Adapter;
- use Zend\Validator\Db\AbstractDb;
- class UserFilter extends InputFilter
- {
- /**
- * @var Adapter
- */
- protected $adapter = null;
- /**
- * Constructor
- *
- * @param Adapter $adapter database adapter
- */
- public function __construct(Adapter $adapter)
- {
- // set database adapter
- $this->adapter = $adapter;
- // add elements
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'id',
- 'required' => true,
- 'filters' => array(
- array('name' => 'Int'),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'cdate',
- 'required' => false,
- 'filters' => array(),
- 'validators' => array(
- array(
- 'name' => 'Date',
- 'options' => array(),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'udate',
- 'required' => false,
- 'filters' => array(),
- 'validators' => array(
- array(
- 'name' => 'Date',
- 'options' => array(),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'adate',
- 'required' => false,
- 'filters' => array(),
- 'validators' => array(
- array(
- 'name' => 'Date',
- 'options' => array(),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'status',
- 'required' => true,
- 'filters' => array(),
- 'validators' => array(
- array(
- 'name' => 'InArray',
- 'options' => array(
- 'haystack' => array('new', 'approved', 'blocked'),
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'group',
- 'required' => true,
- 'filters' => array(),
- 'validators' => array(
- array(
- 'name' => 'InArray',
- 'options' => array(
- 'haystack' => array('guest', 'tourist', 'agency', 'admin'),
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'nickname',
- 'required' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- ),
- 'validators' => array(
- 'stringLength' => array(
- 'name' => 'StringLength',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 1,
- 'max' => 32,
- ),
- ),
- 'dbNoRecordExists' => array(
- 'name' => 'Db\NoRecordExists',
- 'options' => array(
- 'table' => 'users',
- 'field' => 'nickname',
- 'adapter' => $this->adapter,
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'password',
- 'required' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- ),
- 'validators' => array(
- array(
- 'name' => 'StringLength',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 1,
- 'max' => 128,
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'email',
- 'required' => true,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- ),
- 'validators' => array(
- array(
- 'name' => 'EmailAddress',
- 'options' => array(
- ),
- ),
- array(
- 'name' => 'Db\NoRecordExists',
- 'options' => array(
- 'table' => 'users',
- 'field' => 'email',
- 'adapter' => $this->adapter,
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'activation',
- 'required' => false,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- ),
- 'validators' => array(
- array(
- 'name' => 'StringLength',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 32,
- 'max' => 32,
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'firstname',
- 'required' => false,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- ),
- 'validators' => array(
- array(
- 'name' => 'StringLength',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 1,
- 'max' => 64,
- ),
- ),
- ),
- )));
- $this->add($this->getFactory()->createInput(array(
- 'name' => 'lastname',
- 'required' => false,
- 'filters' => array(
- array('name' => 'StripTags'),
- array('name' => 'StringTrim'),
- ),
- 'validators' => array(
- array(
- 'name' => 'StringLength',
- 'options' => array(
- 'encoding' => 'UTF-8',
- 'min' => 1,
- 'max' => 64,
- ),
- ),
- ),
- )));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement