本文整理汇总了PHP中Doctrine_Record::getErrorStack方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Record::getErrorStack方法的具体用法?PHP Doctrine_Record::getErrorStack怎么用?PHP Doctrine_Record::getErrorStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Record
的用法示例。
在下文中一共展示了Doctrine_Record::getErrorStack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
}
}
示例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;
}
示例3: validateRecord
/**
* validates a given record and saves possible errors
* in Doctrine_Validator::$stack
*
* @param Doctrine_Record $record
* @return void
*/
public function validateRecord(Doctrine_Record $record)
{
$columns = $record->getTable()->getColumns();
$component = $record->getTable()->getComponentName();
$errorStack = $record->getErrorStack();
// if record is transient all fields will be validated
// if record is persistent only the modified fields will be validated
$data = $record->exists() ? $record->getModified() : $record->getData();
$err = array();
foreach ($data as $key => $value) {
if ($value === self::$_null) {
$value = null;
} elseif ($value instanceof Doctrine_Record) {
$value = $value->getIncremented();
}
$column = $columns[$key];
if ($column['type'] == 'enum') {
$value = $record->getTable()->enumIndex($key, $value);
if ($value === false) {
$errorStack->add($key, 'enum');
continue;
}
}
if ($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
if (!$this->validateLength($column, $key, $value)) {
$errorStack->add($key, 'length');
continue;
}
}
foreach ($column as $name => $args) {
if (empty($name) || $name == 'primary' || $name == 'protected' || $name == 'autoincrement' || $name == 'default' || $name == 'values' || $name == 'sequence' || $name == 'zerofill') {
continue;
}
if (strtolower($name) == 'length') {
if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
if (!$this->validateLength($column, $key, $value)) {
$errorStack->add($key, 'length');
}
}
continue;
}
if (strtolower($name) == 'type') {
if (!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
if (!self::isValidType($value, $column['type'])) {
$errorStack->add($key, 'type');
}
}
continue;
}
$validator = self::getValidator($name);
if (!$validator->validate($record, $key, $value, $args)) {
$errorStack->add($key, $name);
//$err[$key] = 'not valid';
// errors found quit validation looping for this column
//break;
}
}
if ($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
if (!self::isValidType($value, $column['type'])) {
$errorStack->add($key, 'type');
continue;
}
}
}
}