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


PHP Validator::check方法代码示例

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


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

示例1: testConditionalInRange

 public function testConditionalInRange()
 {
     $values = array('height' => 195, 'gender' => 'M');
     $rules = array('height' => array(array('conditionalInRange', 'message' => 'Incorrect value for given condition!', 'upper' => 201, 'lower' => 184, 'conditions' => array(array('gender', '===', 'M'))), array('conditionalInRange', 'message' => 'Incorrect value for given condition!', 'upper' => 186, 'lower' => 167, 'conditions' => array(array('gender', '===', 'W')))));
     $validate = Validator::check($values, $rules);
     $this->assertTrue(empty($validate));
     $values['gender'] = 'W';
     $validate = Validator::check($values, $rules);
     $this->assertTrue(!empty($validate));
     $values['height'] = 171;
     $validate = Validator::check($values, $rules);
     $this->assertTrue(empty($validate));
     $values['height'] = 165;
     $validate = Validator::check($values, $rules);
     $this->assertTrue(!empty($validate));
 }
开发者ID:djordje,项目名称:li3_validators,代码行数:16,代码来源:CustomTest.php

示例2: testNestedFields

 /**
  * Tests validating nested fields using dot-separated paths.
  */
 public function testNestedFields()
 {
     $rules = array('id' => array('numeric', 'message' => 'Bad ID'), 'profile.name' => "Can't be empty", 'profile.email' => array('email', 'message' => 'Must be a valid email'));
     $data = array('id' => 1, 'profile' => array('email' => 'foo'));
     $result = Validator::check($data, $rules);
     $expected = array('profile.name' => array("Can't be empty"), 'profile.email' => array('Must be a valid email'));
     $this->assertEqual($expected, $result);
     $data = array('id' => '.', 'profile' => array('email' => 'foo@bar.com', 'name' => 'Bob'));
     $result = Validator::check($data, $rules);
     $this->assertEqual(array('id' => array('Bad ID')), $result);
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:14,代码来源:ValidatorTest.php

示例3: validate

 public static function validate($object, $object_hash = array())
 {
     $errors = null;
     if (!in_array(spl_object_hash($object), $object_hash)) {
         $object_hash[] = spl_object_hash($object);
     }
     $reflection = new \ReflectionClass($object);
     $classname = $reflection->getName();
     $validations = $object->validations;
     if (!empty($validations)) {
         $unique = $equalWith = array();
         foreach ($validations as $field => $rules) {
             foreach ($rules as $key => $value) {
                 if ($value[0] == "unique") {
                     $unique[] = array($field, "message" => $value['message']);
                     if (count($validations[$field]) == 1) {
                         unset($validations[$field]);
                     } else {
                         unset($validations[$field][$key]);
                     }
                 } else {
                     if ($value[0] == "equalWith") {
                         $equalWith[] = array($field, "message" => $value['message'], "with" => $value['with']);
                         if (count($validations[$field]) == 1) {
                             unset($validations[$field]);
                         } else {
                             unset($validations[$field][$key]);
                         }
                     }
                 }
             }
         }
         $errors = Validator::check(static::convertToArray($object), $validations);
         /** Unique checking */
         foreach ($unique as $key => $value) {
             $result = $classname::getRepository()->findOneBy(array($value[0] => $object->{$value}[0]));
             if (!empty($result)) {
                 $errors[$value[0]][] = $value["message"];
             }
         }
         /** EqualWith checking */
         foreach ($equalWith as $key => $value) {
             if ($object->{$value}[0] != $object->{$value}['with']) {
                 $errors[$value[0]][] = $value["message"];
             }
         }
         $reflection = new \ReflectionClass($object);
         $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED);
         try {
             foreach ($properties as $property) {
                 $property->setAccessible(true);
                 if (ModelAnnotation::match($property, array('ManyToMany', 'OneToMany'))) {
                     $relation = $property->getValue($object);
                     foreach ($relation as $item) {
                         if (!in_array(spl_object_hash($item), $object_hash)) {
                             if (!ModelValidator::isValid($item, $object_hash)) {
                                 $errors[$property->getName()][] = $item->getErrors();
                             }
                         }
                     }
                 } elseif (ModelAnnotation::match($property, array('ManyToOne', 'OneToOne'))) {
                     if ($item = $property->getValue($object)) {
                         if (!in_array(spl_object_hash($item), $object_hash)) {
                             if (!ModelValidator::isValid($item, $object_hash)) {
                                 $errors[$property->getName()][] = $item->getErrors();
                             }
                         }
                     }
                 }
             }
         } catch (\ReflectionException $e) {
             die($e->getTrace() . "-" . $e->getMessage());
             continue;
         }
     }
     ModelValidator::$_errors[spl_object_hash($object)] = $errors;
     return $errors;
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:78,代码来源:ModelValidator.php

示例4: testValidationWithContextData

 public function testValidationWithContextData()
 {
     Validator::add('someModelRule', function ($value, $format, $options) {
         return $value == 'Title' && $options['values']['body'] == 'Body';
     });
     $result = Validator::check(array('title' => 'Title', 'body' => 'Body'), array('title' => array('someModelRule')));
     $this->assertIdentical(array(), $result);
     $result = Validator::check(array('title' => 'Title', 'body' => 'Not Body'), array('title' => array('someModelRule')));
     $this->assertIdentical(array('title' => array(0)), $result);
 }
开发者ID:EHER,项目名称:chegamos,代码行数:10,代码来源:ValidatorTest.php

示例5: testCheckMultiplePasses

 public function testCheckMultiplePasses()
 {
     $rules = array('title' => 'please enter a title', 'email' => array(array('notEmpty', 'message' => 'email is empty'), array('email', 'message' => 'email is not valid')));
     $data = array('title' => 'new title', 'email' => 'something@test.com');
     $result = Validator::check($data, $rules);
     $this->assertTrue(empty($result));
     $expected = array();
     $this->assertEqual($expected, $result);
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:9,代码来源:ValidatorTest.php

示例6: upload

 /**
  * Call same method on adapter object
  *
  * @filter This method can be filtered.
  *
  * @param string $location
  * @param array $file
  * @param string $destination
  * @param array $options
  * @return boolean
  */
 public static function upload($location, array $file, $destination = null, array $options = array())
 {
     $options += array('validates' => array());
     if (!($adapter = static::_getAdapter($location))) {
         return false;
     }
     static::$uploadErrors = array();
     if (!empty($options['validates']) && is_array($options['validates'])) {
         $errors = Validator::check($file, $options['validates']);
         if (!empty($errors)) {
             static::$uploadErrors = $errors;
             return false;
         }
     }
     $params = compact('file', 'destination', 'options');
     $callback = function ($self, $params) use($adapter) {
         return $adapter->upload($params['file'], $params['destination'], $params['options']);
     };
     return static::_filter(__FUNCTION__, $params, $callback);
 }
开发者ID:djordje,项目名称:li3_filesystem,代码行数:31,代码来源:Filesystem.php


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