/** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return mixed */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $serviceLocator->get('Config'); $zohoConfig = $config['zoho']; $resourceConfig = $config['zoho']['resources'][$requestedName]; $resource = new Resource($zohoConfig['auth_token'], $zohoConfig['organization_id']); $resource->setPath($resourceConfig['path']); $resource->setCollectionName($resourceConfig['collectionName']); $entityClass = array_key_exists('entityClass', $resourceConfig) ? $resourceConfig['entityClass'] : str_replace('Resource', 'Entity', $requestedName); $resource->setEntityClass($entityClass); $resource->setEntityName($resourceConfig['entityName']); if (isset($resourceConfig['input-filter']) && is_array($resourceConfig['input-filter'])) { $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']); $resource->setInputFilter($inputFilter); } $hydratorManager = $serviceLocator->get('HydratorManager'); $hydratorName = str_replace('Entity', 'Hydrator', $entityClass); if ($hydratorManager->has($hydratorName)) { $hydrator = $hydratorManager->get($hydratorName); } else { $hydrator = new ClassMethods(); } $resource->setHydrator($hydrator); return $resource; }
public static function getInputFilter() { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'status', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 65535)))))); return $inputFilter; }
public function getInputFilter() { $factory = new Factory; return $factory->createInputFilter(array( 'type' => 'ZF\Apigility\Admin\InputFilter\Authentication\OAuth2InputFilter', )); }
/** * Init Module form * * @return void */ public function init() { $showEmail = new Element\Checkbox('show_email'); $showEmail->setLabel('Show email'); $showEmail->setAttribute('required', 'required')->setAttribute('id', 'show-email'); $username = new Element\Text('username'); $username->setLabel('Username'); $username->setAttribute('required', 'required')->setAttribute('id', 'username'); $email = new Element\Text('email'); $email->setLabel('Email'); $email->setAttribute('required', 'required')->setAttribute('id', 'email'); $message = new Element\Textarea('message'); $message->setLabel('Message'); $message->setAttribute('required', 'required')->setAttribute('id', 'message'); $captchaImage = new CaptchaImage(array('font' => GC_PUBLIC_PATH . '/backend/fonts/arial.ttf', 'width' => 250, 'height' => 50, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 3)); $captchaImage->setImgDir(GC_PUBLIC_PATH . '/frontend/tmp'); $captchaImage->setImgUrl('/frontend/tmp'); $captcha = new Element\Captcha('captcha'); $captcha->setLabel('Please verify you are human')->setCaptcha($captchaImage)->setAttribute('required', 'required')->setAttribute('id', 'captcha'); $this->add($showEmail); $this->add($username); $this->add($email); $this->add($message); $this->add($captcha); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('show_email' => array('name' => 'show_email', 'required' => false), 'username' => array('name' => 'username', 'required' => true), 'email' => array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'email_address'))), 'message' => array('name' => 'message', 'required' => true), 'captcha' => $captcha->getInputSpecification())); $this->setInputFilter($inputFilter); }
/** * (non-PHPdoc) * * @see \Zend\InputFilter\InputFilterAwareInterface::getInputFilter() */ public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'type', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'title', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'first_name', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'last_name', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'gender', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'date_of_birth', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'address1', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'address2', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'email', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'state', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'country', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'town', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'zip', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'phone', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'amount', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'payment', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'passport_number', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $inputFilter->add($factory->createInput(array('name' => 'order_number', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))))); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
function __construct() { parent::__construct(); $factory = new InputFactory(); $this->add($factory->createInput(array('name' => 'role', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => 'NotEmpty', 'options' => array('messages' => array(\Zend\Validator\NotEmpty::IS_EMPTY => 'Обязательное поле'))))))); $this->add($factory->createInput(array('name' => 'displayName', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => 'NotEmpty', 'options' => array('messages' => array(\Zend\Validator\NotEmpty::IS_EMPTY => 'Обязательное поле'))))))); }
public function init() { $this->setName('ef'); $this->add(array('name' => 'ef-name', 'type' => 'Text', 'attributes' => array('id' => 'ef-name', 'style' => 'width: 320px'), 'options' => array('label' => 'Name'))); $this->add(array('name' => 'ef-description', 'type' => 'Textarea', 'attributes' => array('id' => 'ef-description', 'class' => 'wysiwyg-editor', 'style' => 'width: 320px; height: 180px;'), 'options' => array('label' => 'Description'))); $this->add(array('name' => 'ef-date-start', 'type' => 'Text', 'attributes' => array('id' => 'ef-date-start', 'class' => 'datepicker', 'style' => 'width: 110px;'), 'options' => array('label' => 'Date (Start)'))); $this->add(array('name' => 'ef-time-start', 'type' => 'Text', 'attributes' => array('id' => 'ef-time-start', 'style' => 'width: 110px;'), 'options' => array('label' => 'Time (Start)'))); $this->add(array('name' => 'ef-date-end', 'type' => 'Text', 'attributes' => array('id' => 'ef-date-end', 'class' => 'datepicker', 'style' => 'width: 110px;'), 'options' => array('label' => 'Date (End)'))); $this->add(array('name' => 'ef-time-end', 'type' => 'Text', 'attributes' => array('id' => 'ef-time-end', 'style' => 'width: 110px;'), 'options' => array('label' => 'Time (End)'))); $squareOptions = array('null' => 'All squares'); foreach ($this->squareManager->getAll() as $sid => $square) { $squareOptions[$sid] = $square->get('name'); } $this->add(array('name' => 'ef-sid', 'type' => 'Select', 'attributes' => array('id' => 'ef-sid', 'style' => 'width: 124px'), 'options' => array('label' => 'Square', 'value_options' => $squareOptions))); $this->add(array('name' => 'ef-capacity', 'type' => 'Text', 'attributes' => array('id' => 'ef-capacity', 'style' => 'width: 110px;'), 'options' => array('label' => 'Capacity', 'notes' => 'How many people can participate?'))); $this->add(array('name' => 'ef-notes', 'type' => 'Textarea', 'attributes' => array('id' => 'ef-notes', 'style' => 'width: 250px; height: 48px;'), 'options' => array('label' => 'Notes', 'notes' => 'These are only visible for administration'))); $this->add(array('name' => 'ef-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'ef-submit', 'class' => 'default-button', 'style' => 'width: 200px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('ef-name' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true))), 'ef-description' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'))), 'ef-date-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date')))), 'ef-time-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'ef-date-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date')))), 'ef-time-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'ef-capacity' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Digits', 'options' => array('message' => 'Please type a number here')))), 'ef-notes' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')))))); }
public function getInputFilter() { if (!$this->filter) { $factory = new InputFilterFactory(); $inputFilterSpec = array('id' => array('required' => false), 'block_id' => array('required' => false), 'href' => array('required' => false), 'title' => array('required' => true), 'type' => array('required' => true), 'file' => array('required' => false), 'link' => array('required' => false, 'validators' => array(new UrlValidator())), 'page' => array('required' => false), 'entity_id' => array('required' => false), 'position' => array('required' => false)); $data = $this->data; // if ($this->getName()){ // $name = str_replace(']','', $this->getName()); // $name = explode('[', $name); // while (!empty($name)){ // $key = array_shift($name); // $data = $data[$key]; // } // } switch ($data['type']) { case 'link': $inputFilterSpec['link']['required'] = true; break; case 'page': $inputFilterSpec['page']['required'] = true; break; case 'file': $inputFilterSpec['file']['required'] = true; break; } $this->filter = $factory->createInputFilter($inputFilterSpec); } return $this->filter; }
public function init() { $this->setName('bf'); $this->add(array('name' => 'bf-date-start', 'type' => 'Text', 'attributes' => array('id' => 'bf-date-start', 'style' => 'width: 80px;'), 'options' => array('label' => 'Date (Start)'))); $this->add(array('name' => 'bf-date-end', 'type' => 'Text', 'attributes' => array('id' => 'bf-date-end', 'style' => 'width: 80px;'), 'options' => array('label' => 'Date (End)'))); $this->add(array('name' => 'bf-repeat', 'type' => 'Select', 'attributes' => array('id' => 'bf-repeat', 'style' => 'width: 124px'), 'options' => array('label' => 'Repeat', 'value_options' => Booking::$repeatOptions))); $this->add(array('name' => 'bf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'bf-submit', 'class' => 'default-button', 'style' => 'width: 125px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('bf-date-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date')))), 'bf-date-end' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date'))))))); }
public function init() { $this->setName('eef'); $this->add(array('name' => 'eef-email1', 'type' => 'Text', 'attributes' => array('id' => 'eef-email1', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please provide your email address'))); $this->add(array('name' => 'eef-email2', 'type' => 'Text', 'attributes' => array('id' => 'eef-email2', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please type your email address again<br>to prevent typing errors'))); $this->add(array('name' => 'eef-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Update email address', 'class' => 'default-button'))); /* Input filters */ $userManager = $this->userManager; $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('eef-email1' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'EmailAddress', 'options' => array('useMxCheck' => true, 'message' => 'Please type your correct email address here', 'messages' => array('emailAddressInvalidMxRecord' => 'We could not verify your email provider')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { $blacklist = getcwd() . '/data/res/blacklist-emails.txt'; if (is_readable($blacklist)) { $blacklistContent = file_get_contents($blacklist); $blacklistDomains = explode("\r\n", $blacklistContent); foreach ($blacklistDomains as $blacklistDomain) { $blacklistPattern = str_replace('.', '\\.', $blacklistDomain); if (preg_match('/' . $blacklistPattern . '$/', $value)) { return false; } } } return true; }, 'message' => 'Trash mail addresses are currently blocked - sorry'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) use($userManager) { if ($userManager->getBy(array('email' => $value))) { return false; } else { return true; } }, 'message' => 'This email address has already been registered')))), 'eef-email2' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'eef-email1', 'message' => array('Both email addresses must be identical')))))))); }
/** * Init Module form * * @return void */ public function init() { $this->setAttribute('class', 'relative'); $fileInfo = new Info(); $modulesInfos = array(); $options = array('' => 'Select an option'); foreach ($this->getServiceLocator()->get('ModulesList') as $path => $dir) { $options[$dir] = $dir; $configFile = $path . '/module.info'; if ($fileInfo->fromFile($configFile) === true) { $modulesInfos[$dir] = $fileInfo->render(); } } $collection = new ModuleCollection(); $modules = $collection->getModules(); foreach ($modules as $module) { if (in_array($module->getName(), $options)) { unset($options[$module->getName()]); unset($modulesInfos[$module->getName()]); } } $module = new Element\Select('module'); $module->setLabel('Module')->setLabelAttributes(array('class' => 'required')); $module->setAttribute('id', 'module')->setAttribute('class', 'form-control')->setAttribute('modules_info', $modulesInfos)->setValueOptions($options); $this->add($module); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('module' => array('name' => 'module', 'required' => true, 'validators' => array(array('name' => 'not_empty'))))); $this->setInputFilter($inputFilter); }
public function loginAction() { $form = new LoginForm('', false, $this->getServiceLocator()); $request = $this->getRequest(); if ($request->isPost()) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'username', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty'))))); $inputFilter->add($factory->createInput(array('name' => 'password', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty'))))); $form->setInputFilter($inputFilter); $form->setData($request->getPost()); if ($form->isValid()) { //check authentication... $this->getAuthService()->getAdapter()->setIdentity('' . $request->getPost('username'))->setCredential('' . $request->getPost('password')); $result = $this->getAuthService()->authenticate(); foreach ($result->getMessages() as $message) { //save message temporary into flashmessenger $this->flashmessenger()->addMessage($message); } if ($result->isValid()) { $this->getAuthService()->getStorage()->write($this->getAuthService()->getAdapter()->getResultRowObject(null)); return $this->redirect()->toRoute('bhome'); } } } return array('form' => $form); }
public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); /* $inputFilter->add($factory->createInput(array( 'name' => 'name', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' => 'StringLength', 'options' => array( 'encoding' => 'UTF-8', 'min' => 1, 'max' => 100, ), ), ), ))); */ $inputFilter->add($factory->createInput(array('name' => 'min_start_range', 'required' => true))); $inputFilter->add($factory->createInput(array('name' => 'max_start_range', 'required' => true))); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
function __construct() { $factory = new InputFactory(); $this->add($factory->createInput(array('name' => 'title', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('break_chain_on_failure' => true, 'name' => 'NotEmpty', 'options' => array('messages' => array(\Zend\Validator\NotEmpty::IS_EMPTY => 'Обязательное поле'))))))); $this->add($factory->createInput(array('name' => 'description', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => 'NotEmpty', 'options' => array('messages' => array(\Zend\Validator\NotEmpty::IS_EMPTY => 'Обязательное поле'))))))); $this->add($factory->createInput(array('name' => 'date', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => 'NotEmpty', 'options' => array('messages' => array(\Zend\Validator\NotEmpty::IS_EMPTY => 'Обязательное поле'))))))); }
public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'title', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 5, 'max' => 50)))))); /* $inputFilter->add($factory->createInput(array( 'name' => 'short_note', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' => 'StringLength', 'options' => array( 'encoding' => 'UTF-8', 'min' => 5, 'max' => 500, ), ), ), ))); */ $inputFilter->add($factory->createInput(array('name' => 'field_image', 'required' => false))); $inputFilter->add($factory->createInput(array('name' => 'external_link', 'required' => true))); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
/** * Return a configured input filter to be able to validate and * filter the data. * * @return InputFilter */ public function getInputFilter() { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'user_id', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'), array('name' => 'Int')), 'validators' => array(array('name' => 'NotEmpty'), array('name' => 'Digits'), array('name' => 'Zend\\Validator\\Db\\RecordExists', 'options' => array('table' => 'users', 'field' => 'id', 'adapter' => $this->adapter)))))); return $inputFilter; }
public function init() { $factory = new InputFactory(); $this->add($factory->createInput(array('name' => 'id', 'required' => false))); $this->add($factory->createInput(array('name' => 'mode', 'required' => false, 'filters' => array(array('name' => 'StringTrim'))))); $this->add($factory->createInput(array('name' => 'timecreated', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => $this->_getValidatorSpecification()))); }
public function __invoke(ContainerInterface $container) { $factory = new Factory($container->get(InputFilterPluginManager::class)); $factory->getDefaultFilterChain()->setPluginManager($container->get(FilterPluginManager::class)); $factory->getDefaultValidatorChain()->setPluginManager($container->get(ValidatorPluginManager::class)); return $factory; }
public function getInputFilter() { $factory = new Factory(); return $factory->createInputFilter(array( 'type' => 'ZF\Apigility\Admin\InputFilter\VersionInputFilter', )); }
/** * @return InputFilter */ public function getInputFilter() { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(['name' => 'userId', 'required' => true, 'filters' => [new \Zend\Filter\StripTags(), new \Zend\Filter\StringTrim()]])); return $inputFilter; }
public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(['name' => 'item_id', 'required' => true, 'filters' => array(array("name" => "Int")), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'It was not possible to find the package to change the participant for.'), 'callback' => function ($value, $context = array()) { # check if order with the id of $value exists if (!is_numeric($value)) { return false; } $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $item = $em->getRepository("ErsBase\\Entity\\Item")->findOneBy(array('id' => $value)); if ($item) { return true; } return false; })))])); $inputFilter->add($factory->createInput(['name' => 'user_id', 'required' => true, 'filters' => array(array("name" => "Int")), 'validators' => array(array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'It was not possible to find the user that should be set as participant.'), 'callback' => function ($value, $context = array()) { # check if user with the id of $value exists if (!is_numeric($value)) { return false; } $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('id' => $value)); if ($user) { 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 addInputFilter() { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'leadsUpload', 'required' => true))); $this->setInputFilter($inputFilter); }
public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(['name' => 'firstname', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 45)), array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'The provided name contains invalid character. These charaters are not allowed: !"§$%()=<>|^;{}[]'), 'callback' => function ($value, $context = array()) { $alphabet = '!"§$%()=<>|^;{}[]'; $alpha = str_split($alphabet); foreach ($alpha as $char) { if (strstr($value, $char)) { return false; } } return true; })))])); $inputFilter->add($factory->createInput(['name' => 'surname', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 45)), array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'The provided name contains invalid character. These charaters are not allowed: !"§$%()=<>|^;{}[]'), 'callback' => function ($value, $context = array()) { $alphabet = '!"§$%()=<>|^;{}[]'; $alpha = str_split($alphabet); foreach ($alpha as $char) { if (strstr($value, $char)) { return false; } } return true; })))])); $inputFilter->add($factory->createInput(['name' => 'birthday', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Date', 'options' => array('format' => 'd.m.Y')), array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'Please choose a valid birthday'), 'callback' => function ($value, $context = array()) { $min = \DateTime::createFromFormat('d.m.Y', '01.01.1900'); $max = new \DateTime(); $birthday = \DateTime::createFromFormat('d.m.Y', $value); if (!$birthday instanceof \DateTime) { return false; } if ($min->getTimestamp() > $birthday->getTimestamp()) { return false; } if ($max->getTimestamp() < $birthday->getTimestamp()) { return false; } return true; })))])); $inputFilter->add($factory->createInput(['name' => 'email', 'required' => false, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'EmailAddress', 'options' => array('messages' => array('emailAddressInvalidFormat' => 'Email address format is not invalid'))), array('name' => 'Callback', 'options' => array('messages' => array(\Zend\Validator\Callback::INVALID_VALUE => 'There is already a person with this email address in the system.'), 'callback' => function ($value, $context = array()) { /*if( isset($context['session_id']) && is_numeric($context['session_id']) && $context['session_id'] != 0 ) { return true; }*/ $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('email' => $value)); if ($user && $user->getId() != $context['id']) { return false; } return true; })))])); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
/** * Create and return an InputFilterInputFilter instance. * * @param ContainerInterface $container * @param string $requestedName * @param null|array $options * @return InputFilterInputFilter */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $factory = new InputFilterFactory(); $factory->setInputFilterManager($container->get('InputFilterManager')); $factory->getDefaultFilterChain()->setPluginManager($container->get('FilterManager')); $factory->getDefaultValidatorChain()->setPluginManager($container->get('ValidatorManager')); return new InputFilterInputFilter($factory); }
public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'uid', 'required' => true, 'filters' => array(array('name' => 'Int'))))); } }
/** * Add company_has_user input filter with doctrine validation * * @author Hrayr Shahbazyan * @param \Doctrine\ORM\EntityRepository $companyRepo * @param \Doctrine\ORM\EntityRepository $usersRepo * @return \Zend\InputFilter\InputFilter */ public function addCompanyHasUser($companyRepo, $usersRepo) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter->add($factory->createInput(array('name' => 'user_id', 'required' => true, 'filters' => array(array('name' => 'Int')), 'validators' => array(array('name' => '\\DoctrineModule\\Validator\\ObjectExists', 'options' => array('object_repository' => $usersRepo, 'fields' => 'id', 'messages' => array('noObjectFound' => 'The User does not exist!'))))))); $inputFilter->add($factory->createInput(array('name' => 'company_id', 'required' => true, 'filters' => array(array('name' => 'Int')), 'validators' => array(array('name' => '\\DoctrineModule\\Validator\\ObjectExists', 'options' => array('object_repository' => $companyRepo, 'fields' => 'id', 'messages' => array('noObjectFound' => 'Company does not exist!'))))))); return $inputFilter; }
public function testInputSpecificationFilterIfSecondNotProvided() { $element = new DateTimeSelectElement('test'); $factory = new InputFilterFactory(); $inputFilter = $factory->createInputFilter(array('test' => $element->getInputSpecification())); $inputFilter->setData(array('test' => array('year' => '2013', 'month' => '02', 'day' => '07', 'hour' => '03', 'minute' => '14'))); $this->assertTrue($inputFilter->isValid()); }
public function testCanSetAndGetInputFilter() { $inputFilter = new InputFilter(); $inputFactory = new InputFactory(); $inputFilter->add($inputFactory->createInput(['name' => 'password', 'required' => true, 'validators' => array(['name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Test message')), 'break_chain_on_failure' => true])])); $this->model->setInputFilter($inputFilter); $this->assertEquals($inputFilter, $this->model->getInputFilter()); }
/** * Create service * * @param ServiceLocatorInterface $inputFilters * @return InputFilterInputFilter */ public function createService(ServiceLocatorInterface $inputFilters) { $services = $inputFilters->getServiceLocator(); $factory = new InputFilterFactory(); $factory->setInputFilterManager($inputFilters); $factory->getDefaultFilterChain()->setPluginManager($services->get('FilterManager')); $factory->getDefaultValidatorChain()->setPluginManager($services->get('ValidatorManager')); return new InputFilterInputFilter($factory); }
public function filter($name, $data) { // maybe check if the function exists first $filterArray = $this->{'get' . ucfirst($name) . 'Filters'}(); $factory = new Factory(); $filter = $factory->createInputFilter($filterArray); $filter->setData(array($name => $data)); return $filter; }