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


PHP Doctrine_Validator::validateLength方法代码示例

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


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

示例1: testIsValidLength

 public function testIsValidLength()
 {
     $binaryValue = fread(fopen(__FILE__, 'r'), filesize(__FILE__));
     //Should pass with size the same size as maximum size
     $this->assertTrue(Doctrine_Validator::validateLength($binaryValue, "blob", filesize(__FILE__)));
     //Should fail with maximum size 1 less than actual file size
     $this->assertFalse(Doctrine_Validator::validateLength($binaryValue, "blob", filesize(__FILE__) - 1));
 }
开发者ID:dennybrandes,项目名称:doctrine1,代码行数:8,代码来源:2398TestCase.php

示例2: validateField

 /**
  * validateField
  *
  * @param string $name
  * @param string $value
  * @param Doctrine_Record $record
  * @return Doctrine_Validator_ErrorStack $errorStack
  */
 public function validateField($fieldName, $value, Doctrine_Record $record = null)
 {
     if ($record instanceof Doctrine_Record) {
         $errorStack = $record->getErrorStack();
     } else {
         $record = $this->create();
         $errorStack = new Doctrine_Validator_ErrorStack($this->getOption('name'));
     }
     if ($value === self::$_null) {
         $value = null;
     } else {
         if ($value instanceof Doctrine_Record && $value->exists()) {
             $value = $value->getIncremented();
         } else {
             if ($value instanceof Doctrine_Record && !$value->exists()) {
                 foreach ($this->getRelations() as $relation) {
                     if ($fieldName == $relation->getLocalFieldName() && (get_class($value) == $relation->getClass() || is_subclass_of($value, $relation->getClass()))) {
                         return $errorStack;
                     }
                 }
             }
         }
     }
     $dataType = $this->getTypeOf($fieldName);
     // Validate field type, if type validation is enabled
     if ($this->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_TYPES) {
         if (!Doctrine_Validator::isValidType($value, $dataType)) {
             $errorStack->add($fieldName, 'type');
         }
         if ($dataType == 'enum') {
             $enumIndex = $this->enumIndex($fieldName, $value);
             if ($enumIndex === false && $value !== null) {
                 $errorStack->add($fieldName, 'enum');
             }
         }
     }
     // Validate field length, if length validation is enabled
     if ($this->getAttribute(Doctrine::ATTR_VALIDATE) & Doctrine::VALIDATE_LENGTHS) {
         if (!Doctrine_Validator::validateLength($value, $dataType, $this->getFieldLength($fieldName))) {
             $errorStack->add($fieldName, 'length');
         }
     }
     // Run all custom validators
     foreach ($this->getFieldValidators($fieldName) as $validatorName => $args) {
         if (!is_string($validatorName)) {
             $validatorName = $args;
             $args = array();
         }
         $validator = Doctrine_Validator::getValidator($validatorName);
         $validator->invoker = $record;
         $validator->field = $fieldName;
         $validator->args = $args;
         if (!$validator->validate($value)) {
             $errorStack->add($fieldName, $validator);
         }
     }
     return $errorStack;
 }
开发者ID:mediasadc,项目名称:alba,代码行数:66,代码来源:Table.php

示例3: validateField

 /**
  * Validates a given field using table ATTR_VALIDATE rules.
  * @see Doctrine_Core::ATTR_VALIDATE
  *
  * @param string $fieldName
  * @param string $value
  * @param Doctrine_Record $record   record to consider; if it does not exists, it is created
  * @return Doctrine_Validator_ErrorStack $errorStack
  */
 public function validateField($fieldName, $value, Doctrine_Record $record = null)
 {
     if ($record instanceof Doctrine_Record) {
         $errorStack = $record->getErrorStack();
     } else {
         $record = $this->create();
         $errorStack = new Doctrine_Validator_ErrorStack($this->getOption('name'));
     }
     if ($value === self::$_null) {
         $value = null;
     } else {
         if ($value instanceof Doctrine_Record && $value->exists()) {
             $value = $value->getIncremented();
         } else {
             if ($value instanceof Doctrine_Record && !$value->exists()) {
                 foreach ($this->getRelations() as $relation) {
                     if ($fieldName == $relation->getLocalFieldName() && (get_class($value) == $relation->getClass() || is_subclass_of($value, $relation->getClass()))) {
                         return $errorStack;
                     }
                 }
             } elseif (array_key_exists($fieldName, $this->getRelationIdentifiers()) && $record !== null) {
                 $r = $this->_relationIdentifiers[$fieldName];
                 // Related record is not saved yet
                 if (!$record->hasReference($r) || !$record->{$r}->exists()) {
                     return $errorStack;
                 }
             }
         }
     }
     $dataType = $this->getTypeOf($fieldName);
     // Validate field type, if type validation is enabled
     if ($this->getAttribute(Doctrine_Core::ATTR_VALIDATE) & Doctrine_Core::VALIDATE_TYPES) {
         if (!Doctrine_Validator::isValidType($value, $dataType)) {
             $errorStack->add($fieldName, 'type');
         }
         if ($dataType == 'enum') {
             $enumIndex = $this->enumIndex($fieldName, $value);
             if ($enumIndex === false && $value !== null) {
                 $errorStack->add($fieldName, 'enum');
             }
         }
         if ($dataType == 'set') {
             $values = $this->_columns[$fieldName]['values'];
             // Convert string to array
             if (is_string($value)) {
                 $value = explode(',', $value);
                 foreach ($value as &$v) {
                     $v = trim($v);
                 }
                 $record->set($fieldName, $value);
             }
             // Make sure each set value is valid
             foreach ($value as $k => $v) {
                 if (!in_array($v, $values)) {
                     $errorStack->add($fieldName, 'set');
                 }
             }
         }
     }
     // Validate field length, if length validation is enabled
     if ($this->getAttribute(Doctrine_Core::ATTR_VALIDATE) & Doctrine_Core::VALIDATE_LENGTHS) {
         if (!Doctrine_Validator::validateLength($value, $dataType, $this->getFieldLength($fieldName))) {
             $errorStack->add($fieldName, 'length');
         }
     }
     // Run all custom validators
     foreach ($this->getFieldValidators($fieldName) as $validatorName => $args) {
         if (!is_string($validatorName)) {
             $validatorName = $args;
             $args = array();
         }
         $validator = Doctrine_Validator::getValidator($validatorName);
         $validator->invoker = $record;
         $validator->field = $fieldName;
         $validator->args = $args;
         if (!$validator->validate($value)) {
             $errorStack->add($fieldName, $validator);
         }
     }
     return $errorStack;
 }
开发者ID:sabaki-dev,项目名称:doctrine1,代码行数:90,代码来源:Table.php


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