本文整理匯總了PHP中Doctrine_Validator::getValidator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Doctrine_Validator::getValidator方法的具體用法?PHP Doctrine_Validator::getValidator怎麽用?PHP Doctrine_Validator::getValidator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine_Validator
的用法示例。
在下文中一共展示了Doctrine_Validator::getValidator方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
}
}
}
}
示例6: testMysqlTimestamp
public function testMysqlTimestamp()
{
$timestamp = '2010-03-02 22:08:56';
$timestampValidator = Doctrine_Validator::getValidator('timestamp');
$this->assertTrue($timestampValidator->validate($timestamp));
}