本文整理汇总了PHP中UUID::validUUID方法的典型用法代码示例。如果您正苦于以下问题:PHP UUID::validUUID方法的具体用法?PHP UUID::validUUID怎么用?PHP UUID::validUUID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UUID
的用法示例。
在下文中一共展示了UUID::validUUID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: typeConvert
/**
* Converts the given column name to it's expected container type context (UUID or String)
* @param string $columnName column name
* @param int $toFmt convert to type (UUID::UUID_FMT_BIN, UUID::UUID_FMT_STR)
* @return mixed converted column name
*/
protected function typeConvert($columnName, $toFmt)
{
if ($this->_containerType != self::TYPE_UUID) {
return $columnName;
}
$bin = UUID::isBinary($columnName);
// Save accidental double-conversions on binaries
if ($bin && $toFmt == UUID::UUID_FMT_BIN || !$bin && $toFmt == UUID::UUID_FMT_STR) {
return $columnName;
} elseif (!$bin && !UUID::validUUID($columnName)) {
throw new RuntimeException('Column Name (' . $columnName . ') cannot be converted');
}
return UUID::convert($columnName, $toFmt);
}
示例2: check
//.........这里部分代码省略.........
}
// check for basic validator types
switch ($type) {
case 'notempty':
$error = empty($value);
if ($error) {
$errorMsg[] = "Field cannot be empty";
}
break;
case 'isempty':
// NULL is never allowed, just empty strings
$error = $value != '';
if ($error) {
$errorMsg[] = "Field must be empty";
}
break;
case 'email':
$error = !filter_var($value, FILTER_VALIDATE_EMAIL);
if ($error) {
$errorMsg[] = "Invalid email address";
}
break;
case 'url':
$error = !filter_var($value, FILTER_VALIDATE_URL);
if ($error) {
$errorMsg[] = "Invalid URL";
}
break;
case 'float':
$error = !is_float($value);
if ($error) {
$errorMsg[] = "Field error, expected " . $type;
}
break;
case 'int':
case 'numeric':
$error = !is_numeric($value);
if ($error) {
$errorMsg[] = "Field error, expected " . $type;
}
break;
case 'string':
$error = !is_string($value);
if ($error) {
$errorMsg[] = "Field error, expected " . $type;
}
break;
case 'bool':
$val = strtolower($value);
$boolVals = array('true', 'false', 't', 'f', '1', '0', 'y', 'n');
$error = !is_bool($value) && !in_array($val, $boolVals);
if ($error) {
$errorMsg[] = "Field error, expected " . $type;
}
break;
case 'maxlength':
if (empty($args)) {
throw new RuntimeException("type {$type} requires argument");
}
$error = strlen($value) > $args;
if ($error) {
$errorMsg[] = "Maximum length {$args} exceeded";
}
break;
case 'minlength':
if (empty($args)) {
throw new RuntimeException("type {$type} requires argument");
}
$error = strlen($value) < $args;
if ($error) {
$errorMsg[] = "Minimum length {$args} unmet";
}
break;
case 'enum':
if (empty($args)) {
throw new RuntimeException("type {$type} requires argument");
}
$enums = explode(",", $args);
$error = !in_array($value, $enums);
if ($error) {
$errorMsg[] = "Invalid Argument";
}
break;
case 'uuid':
$error = !UUID::validUUID($value);
if ($error) {
$errorMsg[] = "Invalid UUID (UUID String expected)";
}
break;
default:
throw new RuntimeException("Unhandled type definition ({$type})");
break;
}
}
if (!empty($errorMsg)) {
$errors[] = array($label => $errorMsg);
PandraLog::debug(array($label => $errorMsg));
}
return empty($errorMsg);
}