本文整理汇总了PHP中Doctrine_Validator::validateRecord方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Validator::validateRecord方法的具体用法?PHP Doctrine_Validator::validateRecord怎么用?PHP Doctrine_Validator::validateRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Validator
的用法示例。
在下文中一共展示了Doctrine_Validator::validateRecord方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: 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;
}