示例#1
0
 /**
  * @param array $data
  *
  * @return bool
  */
 public function isValid($data)
 {
     if ($data === null) {
         $data = [];
     }
     $this->inputFilter->setData($data);
     return $this->inputFilter->isValid($data);
 }
 /**
  * Validates the form data using the provided input filter.
  *
  * If validation errors are found, the form is populated with the corresponding error messages.
  * Form values are updated with the clean values provided by the filter.
  *
  * @param  Form $form
  * @return boolean
  */
 public function validate(Form $form)
 {
     $this->inputFilter->setData($form->values());
     if (!($isValid = $this->inputFilter->isValid())) {
         $form->setErrorMessages($this->inputFilter->getMessages());
         return $isValid;
     }
     $form->submit($this->inputFilter->getValues());
     return $isValid;
 }
 /**
  * @param MvcEvent $e
  * @return mixed|void
  */
 public function onDispatch(MvcEvent $e)
 {
     $this->inputFilter->setData($this->params()->fromPost());
     if (!$this->inputFilter->isValid()) {
         $this->flashMessenger()->addErrorMessage($this->inputFilter->getMessages());
         return $this->redirect()->toRoute('frontend');
     }
     try {
         $this->pagesResource->download($this->inputFilter->getValue('site_url'));
         $this->flashMessenger()->addSuccessMessage('Url successfully queued for download all images');
     } catch (ApiException $e) {
         $this->flashMessenger()->addErrorMessage($e->getMessage());
     }
     $this->redirect()->toRoute('frontend');
 }
    /**
     * @param array|stdClass|Traversable $data
     * @return HierarchicalInputFilter
     * @throws InvalidArgumentException
     */
    public function setData($data)
    {
        if ($data instanceof stdClass) {
            $data = Utils::toArray($data);
        }

        // set data and prevent validation of (arrays of) objects by removing the nested input filter
        // note: the actual input filter is not removed because otherwise there would be no container
        //       for the data. setting the input filter to not required is also not necessary because
        //       the data is already set so it's always valid.
        foreach ($this->nestedInputFilters as $name => $nestedInputFilter) {
            if (isset($data[$name])) {
                if (is_object($data[$name]) ||
                   (is_array($data[$name]) && (
                       $this->isContainingObjects($data[$name]) ||
                       (isset($data[$name]['id']) ||
                       (isset($data[$name][0]) && isset($data[$name][0]['id'])))
                   ))
                ) {
                    $this->removeNestedInputFilter($name);
                } else {
                    $nestedInputFilter->setData($data[$name]);
                }
            } else {
                $nestedInputFilter->setData([]);
            }
        }

        parent::setData($data);

        return $this;
    }
示例#5
0
 /**
  * Perform any processing or data manipulation needed before render.
  *
  * A response helper object will be passed to this method to allow you to
  * easily add success messages or redirects.  This helper should be used
  * to handle these kinds of actions so that you can easily test your
  * page's code.
  *
  * @param ResponseHelper $responseHelper
  * @return ResponseHelper|null
  */
 public function process(ResponseHelper $responseHelper)
 {
     $isCurrentUser = $this->row->get('user_id') === Pimple::getResource('user')->get('user_id');
     if (!$this->component->getPermissions()->can('edit') && !$isCurrentUser) {
         return $responseHelper->redirectToUrl('/admin');
     }
     if ($this->request->isPost()) {
         $this->inputFilter->setData($this->request->getPost());
         if ($this->inputFilter->isValid()) {
             $this->row->hashPassword($this->request->getPost('password'))->save();
             if ($isCurrentUser) {
                 return $responseHelper->redirectToUrl('/admin');
             } else {
                 return $responseHelper->redirectToAdminPage('index');
             }
         }
     }
 }
示例#6
0
    /**
     * Overridden to allow for using stdClass
     *
     * @param array|Traversable|stdClass $data
     * @return InputFilterInterface
     * @throws InvalidArgumentException
     */
    public function setData($data)
    {
        if ($data instanceof stdClass) {
            $data = Utils::toArray($data);
        }
        parent::setData($data);

        return $this;
    }
示例#7
0
文件: AtsMode.php 项目: vfulco/YAWIK
 /**
  * Sets data for validating and filtering.
  *
  * @internal
  *  We needed to add dynamically validators, because when "mode" is "intern" or "none" we must
  *  not validate anything. When "mode" is "uri" we must not validate "email address" and we must not
  *  validate "uri" if mode is "uri".
  *
  *  And only when the data is set we do know what has to be validated.
  */
 public function setData($data)
 {
     switch ($data['mode']) {
         default:
             break;
         case AtsModeInterface::MODE_URI:
             $this->add(array('name' => 'uri', 'validators' => array(array('name' => 'uri', 'options' => array('allowRelative' => false)))));
             break;
         case AtsModeInterface::MODE_EMAIL:
             $this->add(array('name' => 'email', 'validators' => array(array('name' => 'EmailAddress'))));
             break;
     }
     return parent::setData($data);
 }
示例#8
0
 /**
  * Sets data for validating and filtering.
  *
  * @internal
  *  We needed to add dynamically validators, because when "mode" is "intern" or "none" we must
  *  not validate anything. When "mode" is "uri" we must not validate "email address" and we must not
  *  validate "uri" if mode is "uri".
  *
  *  And only when the data is set we do know what has to be validated.
  */
 public function setData($data)
 {
     switch ($data['mode']) {
         default:
             break;
         case AtsModeInterface::MODE_URI:
             $this->add(array('name' => 'uri', 'validators' => array(array('name' => 'uri', 'options' => array('allowRelative' => false)))));
             break;
         case AtsModeInterface::MODE_EMAIL:
             $this->add(array('name' => 'email', 'validators' => array(array('name' => 'EmailAddress'))));
             break;
     }
     $this->add(['name' => 'oneClickApplyProfiles', 'required' => $data['mode'] == AtsModeInterface::MODE_INTERN && $data['oneClickApply']]);
     return parent::setData($data);
 }
示例#9
0
 /**
  * __invoke
  *
  * @param Request       $request
  * @param Response      $response
  * @param callable|null $out
  *
  * @return mixed
  */
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $filterConfig = $this->getOption($request, 'config', []);
     $inputFilter = new InputFilter();
     $factory = $inputFilter->getFactory();
     foreach ($filterConfig as $field => $config) {
         $inputFilter->add($factory->createInput($config));
     }
     $dataModel = $request->getParsedBody();
     $inputFilter->setData($dataModel);
     if ($inputFilter->isValid()) {
         return $out($request, $response);
     }
     $messages = new ZfInputFilterMessageResponseModels($inputFilter, $this->getOption($request, 'primaryMessage', 'An Error Occurred'), $this->getOption($request, 'messageParams', []));
     return $this->getResponseWithDataBody($response, $messages);
 }
示例#10
0
 /**
  * @return InputFilter
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new InputFilter();
         //input filter para campo id
         $inputFilter->add(array('name' => 'id_aluno', 'required' => true, 'filters' => array(array('name' => 'Int'))));
         //input filter para campo de nome
         $inputFilter->add(array('name' => 'nome_aluno', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 3, 'max' => 100, 'messages' => array(StringLength::TOO_SHORT => 'Mínimo de caracteres aceitáveis %min%.', StringLength::TOO_LONG => 'Máximo de caracteres aceitáveis %max%.'))))));
         //input filter para campo matricula
         $inputFilter->add(array('name' => 'matricula_aluno', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 3, 'max' => 100, 'messages' => array(StringLength::TOO_SHORT => 'Mínimo de caracteres aceitáveis %min%.', StringLength::TOO_LONG => 'Máximo de caracteres aceitáveis %max%.'))))));
         //input filter para campo curso
         $inputFilter->add(array('name' => 'curso_aluno', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8')))));
         //input filter para campo serie
         $inputFilter->add(array('name' => 'serie_aluno', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8')))));
         //input filter para campo materia
         $inputFilter->add(array('name' => 'materia_aluno', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8')))));
         //input filter para campo curso
         $inputFilter->add(array('name' => 'professor_aluno', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))), array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8')))));
         //input filter para nota provas
         $inputFilter->add(array('name' => 'prova1', 'required' => false));
         $inputFilter->add(array('name' => 'prova2', 'required' => false));
         $inputFilter->add(array('name' => 'prova3', 'required' => false));
         $inputFilter->add(array('name' => 'prova4', 'required' => false));
         //input filter para nota trabalhos
         $inputFilter->add(array('name' => 'trabalho1', 'required' => false));
         $inputFilter->add(array('name' => 'trabalho2', 'required' => false));
         $inputFilter->add(array('name' => 'trabalho3', 'required' => false));
         $inputFilter->add(array('name' => 'trabalho4', 'required' => false));
         //input faltas
         $inputFilter->add(array('name' => 'faltas', 'required' => false, 'filters' => array(array('name' => 'Int'))));
         //input situacao
         $inputFilter->add(array('name' => 'situacao_aluno', 'required' => true, 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array(NotEmpty::IS_EMPTY => 'Campo obrigatório.'))))));
         $inputFilter->setData(array('float' => '1.234,56', 'integer' => '1.234', 'nfloat' => '-1.234,56', 'ninteger' => '-1.234'));
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
示例#11
0
 /**
  * Set data to use when validating and filtering
  *
  * @param array|Traversable $data
  * @return BaseFilter
  */
 public function setData($data)
 {
     // setData() expects array, but we can't prevent users from providing other types.
     // So instead of an exception we just want this input filter to be invalid...
     try {
         parent::setData($data);
         $this->invalidData = null;
         $this->invalidDataTypeException = null;
     } catch (InputFilterInvalidArgumentException $e) {
         $this->invalidData = $data;
         $this->invalidDataTypeException = $e;
     }
     return $this;
 }
示例#12
0
 /**
  * @param array|\Traversable $data
  * @return bool|null|\Zend\InputFilter\InputFilterInterface
  */
 public function setData($data)
 {
     $this->isValid = null;
     return parent::setData($data);
 }
示例#13
0
 /**
  *
  * @see \Zend\InputFilter\BaseInputFilter::setData()
  */
 public function setData($data)
 {
     $this->add(['name' => 'endDate', 'required' => !$data['currentIndicator']]);
     return parent::setData($data);
 }
示例#14
0
 /**
  * Only proceed to process() method if the request is a POST.
  *
  * If the request _is_ a POST, pass the POST data along to the fields
  * object and the input filter.
  *
  * @return boolean
  */
 public function shouldProcess()
 {
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         $this->fields->setValues($post);
         $this->inputFilter->setData($post);
         return true;
     }
     return false;
 }
示例#15
0
 /**
  * Set data to use when validating and filtering
  * - We wait to build the fields until setData is called
  *
  * @param  array|Traversable $data
  *
  * @return \Zend\InputFilter\InputFilterInterface
  */
 public function setData($data)
 {
     $this->build($data);
     return parent::setData($data);
 }
示例#16
0
 /**
  * Override to validate only what is actually present in data.
  * This allow for user to submit incomplete data
  * @param array $data
  * @return mixed
  */
 public function setData($data)
 {
     $this->setValidationGroup(array_keys($data));
     return parent::setData($data);
 }