本文整理汇总了PHP中AbstractModel::getFieldTypes方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getFieldTypes方法的具体用法?PHP AbstractModel::getFieldTypes怎么用?PHP AbstractModel::getFieldTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::getFieldTypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkFieldList
/**
* @param AbstractModel $className
* @return array
*/
protected final function checkFieldList($className)
{
$errors = [];
// on vérifie d'abord que la table est définie
$tableName = $className::getTableName();
if ($tableName === null || !is_string($tableName) || strlen($tableName) == 0) {
$errors[] = "undefined table name";
}
$fieldList = $className::getFieldList();
if ($fieldList === null) {
$errors[] = "undefined field list";
} elseif (!is_array($fieldList)) {
$errors[] = "field list is not an array";
} else {
foreach ($fieldList as $fieldName => $fieldInfos) {
if (!is_string($fieldName) || strlen($fieldName) == 0) {
$errors[] = "undefined field name in field list";
} else {
if (!isset($fieldInfos['type'])) {
$errors[] = "undefined field type for field named " . $fieldName;
} elseif (!in_array($fieldInfos['type'], AbstractModel::getFieldTypes())) {
$errors[] = "unknown field type for field named " . $fieldName . " : " . $fieldInfos['type'];
}
if (!isset($fieldInfos['required'])) {
$fieldList[$fieldName]['required'] = false;
} elseif (!is_bool($fieldInfos['required'])) {
$errors[] = "invalid required value for field named " . $fieldName . " : " . $fieldInfos['required'];
}
if (!isset($fieldInfos['size'])) {
$fieldList[$fieldName]['size'] = 0;
} elseif ($fieldInfos['type'] == 'float' && preg_match('#[0-9]+,[0-9]+#', $fieldInfos['size']) === false) {
$errors[] = "invalid size for field named " . $fieldName . " (" . $fieldInfos['type'] . ") : " . $fieldInfos['size'];
} elseif ($fieldInfos['type'] != 'float' && !is_int($fieldInfos['size'])) {
$errors[] = "size must be integer for field named " . $fieldName . " (" . $fieldInfos['type'] . ") : " . $fieldInfos['size'];
}
}
}
}
$relationList = $className::getRelationList();
if ($relationList === null) {
$errors[] = "undefined relation list";
} elseif (!is_array($relationList)) {
$errors[] = "relation list is not an array";
} else {
foreach ($relationList as $relation) {
if (!isset($relation['field'])) {
$errors[] = "missing field on relation";
}
if (!isset($relation['class'])) {
$errors[] = "missing class on relation";
}
if (!isset($fieldList[$relation['field']])) {
$errors[] = "unknown field name in relation " . $relation['field'];
}
if (!is_subclass_of($relation['class'], '\\Bixev\\ORM\\AbstractModel')) {
$errors[] = "relation is not a model " . $relation['class'];
}
}
}
return $errors;
}