當前位置: 首頁>>代碼示例>>PHP>>正文


PHP InputFilter::setData方法代碼示例

本文整理匯總了PHP中Zend\InputFilter\InputFilter::setData方法的典型用法代碼示例。如果您正苦於以下問題:PHP InputFilter::setData方法的具體用法?PHP InputFilter::setData怎麽用?PHP InputFilter::setData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\InputFilter\InputFilter的用法示例。


在下文中一共展示了InputFilter::setData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isValid

 /**
  * @param array $data
  *
  * @return bool
  */
 public function isValid($data)
 {
     if ($data === null) {
         $data = [];
     }
     $this->inputFilter->setData($data);
     return $this->inputFilter->isValid($data);
 }
開發者ID:t4web,項目名稱:crud,代碼行數:13,代碼來源:BaseValidator.php

示例2: validate

 /**
  * 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;
 }
開發者ID:comphppuebla,項目名稱:easy-forms,代碼行數:19,代碼來源:InputFilterValidator.php

示例3: onDispatch

 /**
  * @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');
 }
開發者ID:spalax,項目名稱:eu-webchalange-download-images-api,代碼行數:19,代碼來源:AddController.php

示例4: setData

    /**
     * @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;
    }
開發者ID:jbarentsen,項目名稱:drb,代碼行數:37,代碼來源:HierarchicalInputFilter.php

示例5: process

 /**
  * 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');
             }
         }
     }
 }
開發者ID:deltasystems,項目名稱:dewdrop,代碼行數:29,代碼來源:ChangePassword.php

示例6: setData

    /**
     * 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;
    }
開發者ID:jbarentsen,項目名稱:drb,代碼行數:16,代碼來源:InputFilter.php

示例7: setData

 /**
  * 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);
 }
開發者ID:vfulco,項目名稱:YAWIK,代碼行數:24,代碼來源:AtsMode.php

示例8: setData

 /**
  * 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);
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:25,代碼來源:AtsMode.php

示例9: __invoke

 /**
  * __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);
 }
開發者ID:reliv,項目名稱:pipe-rat,代碼行數:25,代碼來源:ZfInputFilterConfig.php

示例10: getInputFilter

 /**
  * @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;
 }
開發者ID:breakx,項目名稱:SistemaEscolar,代碼行數:40,代碼來源:Aluno.php

示例11: setData

 /**
  * 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;
 }
開發者ID:detailnet,項目名稱:dfw-filtering,代碼行數:20,代碼來源:BaseFilter.php

示例12: setData

 /**
  * @param array|\Traversable $data
  * @return bool|null|\Zend\InputFilter\InputFilterInterface
  */
 public function setData($data)
 {
     $this->isValid = null;
     return parent::setData($data);
 }
開發者ID:spalax,項目名稱:zf2-libs,代碼行數:9,代碼來源:AbstractInputFilter.php

示例13: setData

 /**
  *
  * @see \Zend\InputFilter\BaseInputFilter::setData()
  */
 public function setData($data)
 {
     $this->add(['name' => 'endDate', 'required' => !$data['currentIndicator']]);
     return parent::setData($data);
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:9,代碼來源:Employment.php

示例14: shouldProcess

 /**
  * 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;
 }
開發者ID:bravadomizzou,項目名稱:dewdrop,代碼行數:18,代碼來源:EditAbstract.php

示例15: setData

 /**
  * 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);
 }
開發者ID:reliv,項目名稱:rcm-user,代碼行數:13,代碼來源:LoginInputFilter.php


注:本文中的Zend\InputFilter\InputFilter::setData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。