當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。