/** * Validiert den übergebenen Namen * @param string $name * @return Alliance * @throws \DragonJsonServer\Exception */ public function validateName($name) { $filter = new \Zend\Filter\StringTrim(); if ($name != $filter->filter($name)) { throw new \DragonJsonServer\Exception('invalid name', ['name' => $name]); } $namelength = $this->getServiceManager()->get('Config')['dragonjsonserveralliance']['namelength']; $validator = (new \Zend\Validator\StringLength())->setMin($namelength['min'])->setMax($namelength['max']); if (!$validator->isValid($name)) { throw new \DragonJsonServer\Exception('invalid name', ['name' => $name, 'namelength' => $namelength]); } return $this; }
public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(['name' => 'BankStatement_id', 'required' => true, 'filters' => array(array("name" => "Callback", "options" => array("callback" => function ($values) { $strip = new \Zend\Filter\StripTags(); $trim = new \Zend\Filter\StringTrim(); $int = new \Zend\Filter\Int(); foreach ($values as $key => $val) { $val = $strip->filter($val); $val = $trim->filter($val); $val = $int->filter($val); $values[$key] = $val; } return $values; }))), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Please choose either one statement and multiple orders or multiple statements and one order.'), 'callback' => function ($values, $context = array()) { if (count($values) == 1 && count($context['Order_id']) >= 1) { return true; } if (count($values) >= 1 && count($context['Order_id']) == 1) { return true; } return false; })))])); $inputFilter->add($factory->createInput(['name' => 'Order_id', 'required' => true, 'filters' => array(array("name" => "Callback", "options" => array("callback" => function ($values) { $strip = new \Zend\Filter\StripTags(); $trim = new \Zend\Filter\StringTrim(); $int = new \Zend\Filter\Int(); foreach ($values as $key => $val) { $val = $strip->filter($val); $val = $trim->filter($val); $val = $int->filter($val); $values[$key] = $val; } return $values; }))), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Please choose either one order and multiple statements or multiple orders and one statement.'), 'callback' => function ($values, $context = array()) { if (count($values) == 1 && count($context['BankStatement_id']) >= 1) { return true; } if (count($values) >= 1 && count($context['BankStatement_id']) == 1) { return true; } return false; })))])); $inputFilter->add($factory->createInput(['name' => 'comment', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty'))])); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
public function index09Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; $filter = new \Zend\Filter\StringTrim(); $input = " \$%#\$\$%dsgsdgs123 "; $output = $filter->filter($input); echo "<h2>Input: {$input}</h2><br>"; echo "<h2>Output : {$output}</h2>"; return false; }
public function getInputFilter() { $this->inputFilter = new InputFilter(); $factory = new InputFactory(); $this->inputFilter->add($factory->createInput(['name' => 'Product_id', 'required' => true, 'filters' => array(array('name' => 'Int')), 'validators' => array()])); $this->inputFilter->add($factory->createInput(['name' => 'participant_id', 'required' => true, 'filters' => array(array('name' => 'Int')), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Please select a person.'), 'callback' => function ($value, $context = array()) { if (is_numeric($value)) { return true; } if (isset($context['agegroup_id']) && is_numeric($context['agegroup_id'])) { return true; } return false; })), array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Unable to add personalized product to person without birthdate. Please add date of birth in My Person list.'), 'callback' => function ($value, $context = array()) { $cartContainer = new Container('cart'); $participant = $cartContainer->order->getParticipantById($value); if (is_object($participant)) { if (!$participant->getBirthday() instanceof \DateTime) { return false; } else { return true; } } else { # this is not a personalized product return true; } })))])); $this->inputFilter->add($factory->createInput(['name' => 'agegroup_id', 'required' => true, 'filters' => array(array('name' => 'Int')), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Please select a agegroup.'), 'callback' => function ($value, $context = array()) { if (is_numeric($value)) { return true; } if (isset($context['participant_id']) && is_numeric($context['participant_id'])) { return true; } return false; })))])); $this->inputFilter->add($factory->createInput(['name' => 'pv', 'required' => true, 'filters' => array(array("name" => "Callback", "options" => array("callback" => function ($values) { #$int = new \Zend\Filter\Int(); $strip = new \Zend\Filter\StripTags(); $trim = new \Zend\Filter\StringTrim(); foreach ($values as $key => $value) { #$value = $int->filter($value); $value = $strip->filter($value); $value = $trim->filter($value); $values[$key] = $value; } return $values; }))), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Please select a product variant.'), 'callback' => function ($values, $context = array()) { foreach ($values as $key => $value) { if ($value == '') { return false; } if (!is_numeric($value)) { return false; } } return true; })))])); return $this->inputFilter; }