当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::setFilters方法代码示例

本文整理汇总了PHP中Phalcon\Validation::setFilters方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::setFilters方法的具体用法?PHP Validation::setFilters怎么用?PHP Validation::setFilters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Validation的用法示例。


在下文中一共展示了Validation::setFilters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validator

 public function validator(\Phalcon\Validation $validation, array $rules, array $urlParams)
 {
     $conut = 0;
     $this->composeCheckData();
     $newRule = array();
     if (isset($rules['url'])) {
         $this->setUrlParToData($rules['url'], $urlParams);
         $newRule[] = $rules['url'];
     }
     if (isset($rules['post']) && $this->method == 'POST') {
         $newRule[] = $rules['post'];
     }
     if (isset($rules['get']) && $this->method == 'GET') {
         $newRule[] = $rules['get'];
     }
     if (count($newRule) < 1) {
         return true;
     }
     foreach ($newRule as $value) {
         foreach ($value as $subKey => $subValue) {
             if (4 > count($subValue)) {
                 throw new \common\form\FormException("the rules config error about key:" . $subKey, 11003);
                 return;
             }
             $must = isset($subValue[4]) ? $subValue[4] : true;
             $isset = isset($this->formData[$subKey]);
             if (false == $must && (false == $isset || true == $isset && empty($this->formData[$subKey]))) {
                 continue;
             }
             $conut++;
             $validation->add($subKey, \core\RuleBase::setRules($subValue[0], $subValue[1], array($subValue[2], $subValue[3])));
             $validation->setFilters($subKey, 'trim');
         }
     }
     if ($conut) {
         return $validation->validate($this->formData);
     }
     return true;
 }
开发者ID:nicklos17,项目名称:eapi,代码行数:39,代码来源:FormParse.php

示例2: testValidationFiltering

 public function testValidationFiltering()
 {
     $this->specify("Validation filtering doesn't work as expected", function () {
         $validation = new Validation();
         $validation->setDI(new FactoryDefault());
         $validation->add('name', new Validation\Validator\PresenceOf(array('message' => 'The name is required')))->add('email', new Validation\Validator\PresenceOf(array('message' => 'The email is required')));
         $validation->setFilters('name', 'trim');
         $validation->setFilters('email', 'trim');
         $messages = $validation->validate(['name' => '  ', 'email' => '    ']);
         expect($messages)->count(2);
         $filtered = $messages->filter('email');
         $expectedMessages = array(0 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The email is required', '_field' => 'email', '_code' => '0')));
         expect($filtered)->equals($expectedMessages);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:15,代码来源:ValidationTest.php

示例3: isValid

 /**
  * Validates the form
  *
  * @param array|null $data
  * @param object|null $entity
  * @return boolean
  * @throws Exception
  */
 public function isValid($data = null, $entity = null)
 {
     if (is_array($data) === false && is_null($data) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if (is_object($entity) === false && is_null($entity) === false) {
         throw new Exception('Invalid parameter type.');
     }
     if (is_array($this->_elements) === false) {
         return true;
     }
     //If the user doesn't pass an entity we use the one in this_ptr->_entity
     //@note the text does not match the === true but that's how it is
     if (is_object($entity) === true) {
         $this->bind($data, $entity);
     }
     //If the data is not an array use the one passed previously
     if (is_array($data) === false) {
         $data = $this->_data;
     }
     //Check if there is a method 'beforeValidation'
     if (method_exists($this, 'beforeValidation') === true) {
         if ($this->beforeValidation($data, $entity) === false) {
             return false;
         }
     }
     $notFailed = true;
     $messages = array();
     foreach ($this->_elements as $element) {
         $validators = $element->getValidators();
         if (is_array($validators) === true && empty($validators) === false) {
             $name = $element->getName();
             $preparedValidators = array();
             foreach ($validators as $validator) {
                 $preparedValidators[] = array($name, $validator);
             }
             //Create an implicit validator
             $validation = new Validation($preparedValidators);
             //Get filters in the element
             $filters = $element->getFilters();
             //Assign the filters to the validation
             if (is_array($filters) === true) {
                 $name = $element->getName();
                 $validation->setFilters($name, $filters);
             }
             //Perform the validation
             $elementMessages = $validation->validate($data, $entity);
             if (empty($elementMessages) === false) {
                 $name = $element->getName();
                 $messages[$name] = $elementMessages;
                 $notFailed = false;
             }
         }
     }
     //If the validation fails we update the messages
     if ($notFailed === false) {
         $this->_messages = $messages;
     }
     //Check if there is a method 'afterValidation'
     if (method_exists($this, 'afterValidation') === true) {
         $this->afterValidation($messages);
     }
     return $notFailed;
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:72,代码来源:Form.php


注:本文中的Phalcon\Validation::setFilters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。