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


PHP UUID::validUUID方法代码示例

本文整理汇总了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);
 }
开发者ID:jlaprise,项目名称:Pandra,代码行数:20,代码来源:ColumnContainer.class.php

示例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);
 }
开发者ID:ruflin,项目名称:Pandra,代码行数:101,代码来源:Validator.class.php


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