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


PHP Doctrine_Validator类代码示例

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


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

示例1: isValid

 /**
  * tests validity of the record using the current data.
  *
  * (This is an override of base Doctrine functionality, to fix a bug with validation.)
  *
  * @param boolean $deep  (optional) run the validation process on the relations
  * @param boolean $hooks (optional) invoke save hooks before start
  * @return boolean        whether or not this record is valid
  */
 public function isValid($deep = false, $hooks = true)
 {
     if (!$this->_table->getAttribute(Doctrine_Core::ATTR_VALIDATE)) {
         return true;
     }
     if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) {
         return true;
     }
     if ($hooks) {
         $this->invokeSaveHooks('pre', 'save');
         $this->invokeSaveHooks('pre', $this->exists() ? 'update' : 'insert');
     }
     // Clear the stack from any previous errors.
     $this->getErrorStack()->clear();
     // Run validation process
     $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE);
     $this->preValidate($event);
     $this->getTable()->getRecordListener()->preValidate($event);
     if (!$event->skipOperation) {
         $validator = new Doctrine_Validator();
         $validator->validateRecord($this);
         $this->validate();
         if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) {
             $this->validateOnInsert();
         } else {
             $this->validateOnUpdate();
         }
     }
     $this->getTable()->getRecordListener()->postValidate($event);
     $this->postValidate($event);
     $valid = $this->getErrorStack()->count() == 0 ? true : false;
     if ($valid && $deep) {
         $stateBeforeLock = $this->_state;
         $this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED;
         foreach ($this->_references as $reference) {
             if ($reference instanceof Doctrine_Record) {
                 if (!($valid = $reference->isValid($deep))) {
                     break;
                 }
             } elseif ($reference instanceof Doctrine_Collection) {
                 foreach ($reference as $record) {
                     if (!($valid = $record->isValid($deep, $hooks))) {
                         break;
                     }
                 }
                 // Bugfix.
                 if (!$valid) {
                     break;
                 }
             }
         }
         $this->_state = $stateBeforeLock;
     }
     return $valid;
 }
开发者ID:kaakshay,项目名称:audience-insight-repository,代码行数:64,代码来源:AIR2_Record.php

示例2: 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

示例3: validate

 /**
  * checks if given value is a valid ISO-8601 timestamp (YYYY-MM-DDTHH:MM:SS+00:00)
  *
  * @param mixed $value
  * @return boolean
  */
 public function validate($value)
 {
     if (is_null($value)) {
         return true;
     }
     $e = explode('T', trim($value));
     $date = isset($e[0]) ? $e[0] : null;
     $time = isset($e[1]) ? $e[1] : null;
     $dateValidator = Doctrine_Validator::getValidator('date');
     $timeValidator = Doctrine_Validator::getValidator('time');
     if (!$dateValidator->validate($date)) {
         return false;
     }
     if (!$timeValidator->validate($time)) {
         return false;
     }
     return true;
 }
开发者ID:atikahmed,项目名称:joomla-probid,代码行数:24,代码来源:Timestamp.php

示例4: validate

 /**
  * checks if given value is a valid timestamp
  * ISO-8601 timestamp (YYYY-MM-DDTHH:MM:SS+00:00) or (YYYY-MM-DD HH:MM:SS)
  *
  * @param mixed $value
  * @return boolean
  */
 public function validate($value)
 {
     if (is_null($value)) {
         return true;
     }
     $splitChar = false !== strpos($value, 'T') ? 'T' : ' ';
     $e = explode($splitChar, trim($value));
     $date = isset($e[0]) ? $e[0] : null;
     $time = isset($e[1]) ? $e[1] : null;
     $dateValidator = Doctrine_Validator::getValidator('date');
     $timeValidator = Doctrine_Validator::getValidator('time');
     if (!$dateValidator->validate($date)) {
         return false;
     }
     if (!$timeValidator->validate($time)) {
         return false;
     }
     return true;
 }
开发者ID:seven07ve,项目名称:vendorepuestos,代码行数:26,代码来源:Timestamp.php

示例5: validate

 /**
  * checks if given value is a valid timestamp (YYYY-MM-DD HH:MM:SS)
  *
  * @param mixed $value
  * @return boolean
  */
 public function validate($value)
 {
     if ($value === null) {
         return true;
     }
     if (!preg_match('/^ *\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(.\\d{6}\\+\\d{2})? *$/', $value)) {
         return false;
     }
     list($date, $time) = explode(' ', trim($value));
     $dateValidator = Doctrine_Validator::getValidator('date');
     $timeValidator = Doctrine_Validator::getValidator('time');
     if (!$dateValidator->validate($date)) {
         return false;
     }
     if (!$timeValidator->validate($time)) {
         return false;
     }
     return true;
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:25,代码来源:Timestamp.php

示例6: 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

示例7: isValid

 /**
  * isValid
  *
  * @return boolean  whether or not this record is valid
  */
 public function isValid()
 {
     if (!$this->_table->getAttribute(Doctrine::ATTR_VALIDATE)) {
         return true;
     }
     // Clear the stack from any previous errors.
     $this->getErrorStack()->clear();
     // Run validation process
     $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE);
     $this->preValidate($event);
     $this->getTable()->getRecordListener()->preValidate($event);
     if (!$event->skipOperation) {
         $validator = new Doctrine_Validator();
         $validator->validateRecord($this);
         $this->validate();
         if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) {
             $this->validateOnInsert();
         } else {
             $this->validateOnUpdate();
         }
     }
     $this->getTable()->getRecordListener()->postValidate($event);
     $this->postValidate($event);
     return $this->getErrorStack()->count() == 0 ? true : false;
 }
开发者ID:njch,项目名称:PatBati,代码行数:30,代码来源:Record.php

示例8: checkValidation

 public function checkValidation($deep = true, $hooks = true)
 {
     $invalidRecords = array();
     if (!$this->_table->getAttribute(Doctrine::ATTR_VALIDATE)) {
         return true;
     }
     if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) {
         return true;
     }
     if ($hooks) {
         $this->invokeSaveHooks('pre', 'save');
         $this->invokeSaveHooks('pre', $this->exists() ? 'update' : 'insert');
     }
     // Clear the stack from any previous errors.
     $this->getErrorStack()->clear();
     // Run validation process
     $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE);
     $this->preValidate($event);
     $this->getTable()->getRecordListener()->preValidate($event);
     if (!$event->skipOperation) {
         $validator = new Doctrine_Validator();
         $validator->validateRecord($this);
         $this->validate();
         if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) {
             $this->validateOnInsert();
         } else {
             $this->validateOnUpdate();
         }
     }
     $this->getTable()->getRecordListener()->postValidate($event);
     $this->postValidate($event);
     $valid = $this->getErrorStack()->count() == 0 ? true : false;
     if (!$valid) {
         $invalidRecords[] = $this;
     }
     if ($deep) {
         $stateBeforeLock = $this->_state;
         $this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED;
         foreach ($this->_references as $reference) {
             if ($reference instanceof Doctrine_Record) {
                 if (!method_exists($reference, 'checkValidation')) {
                     continue;
                 }
                 $valid = $reference->checkValidation($deep);
                 if (is_array($valid) && !empty($valid)) {
                     $invalidRecords = array_merge($valid, $invalidRecords);
                 }
             } else {
                 if ($reference instanceof Doctrine_Collection) {
                     foreach ($reference as $record) {
                         if (!method_exists($record, 'checkValidation')) {
                             continue;
                         }
                         $valid = $record->checkValidation($deep);
                         if (is_array($valid) && !empty($valid)) {
                             $invalidRecords = array_merge($valid, $invalidRecords);
                         }
                     }
                 }
             }
         }
         $this->_state = $stateBeforeLock;
     }
     return $invalidRecords;
 }
开发者ID:swk,项目名称:bluebox,代码行数:65,代码来源:Bluebox_Record.php

示例9: validateUniques

 /**
  * Validates all the unique indexes.
  *
  * This methods validates 'unique' sets of fields for the given Doctrine_Record instance.
  * Pushes error to the record error stack if they are generated.
  *
  * @param Doctrine_Record $record
  */
 public function validateUniques(Doctrine_Record $record)
 {
     $errorStack = $record->getErrorStack();
     $validator = Doctrine_Validator::getValidator('unique');
     $validator->invoker = $record;
     foreach ($this->_uniques as $unique) {
         list($fields, $options) = $unique;
         $validator->args = $options;
         $validator->field = $fields;
         $values = array();
         foreach ($fields as $field) {
             $values[] = $record->{$field};
         }
         if (!$validator->validate($values)) {
             foreach ($fields as $field) {
                 $errorStack->add($field, $validator);
             }
         }
     }
 }
开发者ID:aldimol,项目名称:zf-sample,代码行数:28,代码来源:Table.php

示例10: testValidate

 public function testValidate()
 {
     $this->manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
     $user = $this->connection->getTable('User')->find(4);
     $set = array('password' => 'this is an example of too long password', 'loginname' => 'this is an example of too long loginname', 'name' => 'valid name', 'created' => 'invalid');
     $user->setArray($set);
     $email = $user->Email;
     $email->address = 'zYne@invalid';
     $this->assertTrue($user->getModified() == $set);
     $validator = new Doctrine_Validator();
     $validator->validateRecord($user);
     $stack = $user->errorStack();
     $this->assertTrue($stack instanceof Doctrine_Validator_ErrorStack);
     $this->assertTrue(in_array('length', $stack['loginname']));
     $this->assertTrue(in_array('length', $stack['password']));
     $this->assertTrue(in_array('type', $stack['created']));
     $validator->validateRecord($email);
     $stack = $email->errorStack();
     $this->assertTrue(in_array('email', $stack['address']));
     $email->address = 'arnold@example.com';
     $validator->validateRecord($email);
     $stack = $email->errorStack();
     $this->assertTrue(in_array('unique', $stack['address']));
     $this->manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_NONE);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:25,代码来源:ValidatorTestCase.php

示例11: isValid

 /**
  * isValid
  *
  * @return boolean  whether or not this record is valid
  */
 public function isValid()
 {
     if (!$this->_table->getAttribute(Doctrine::ATTR_VALIDATE)) {
         return true;
     }
     // Clear the stack from any previous errors.
     $this->_errorStack->clear();
     // Run validation process
     $validator = new Doctrine_Validator();
     $validator->validateRecord($this);
     $this->validate();
     if ($this->_state == self::STATE_TDIRTY || $this->_state == self::STATE_TCLEAN) {
         $this->validateOnInsert();
     } else {
         $this->validateOnUpdate();
     }
     return $this->_errorStack->count() == 0 ? true : false;
 }
开发者ID:walterfrs,项目名称:mladek,代码行数:23,代码来源:Record.php

示例12: testMysqlTimestamp

 public function testMysqlTimestamp()
 {
     $timestamp = '2010-03-02 22:08:56';
     $timestampValidator = Doctrine_Validator::getValidator('timestamp');
     $this->assertTrue($timestampValidator->validate($timestamp));
 }
开发者ID:vbryan,项目名称:Zend,代码行数:6,代码来源:DC848TestCase.php


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