本文整理匯總了PHP中RedBeanPHP\OODBBean::box方法的典型用法代碼示例。如果您正苦於以下問題:PHP OODBBean::box方法的具體用法?PHP OODBBean::box怎麽用?PHP OODBBean::box使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類RedBeanPHP\OODBBean
的用法示例。
在下文中一共展示了OODBBean::box方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validate
public static function validate(\RedBeanPHP\OODBBean $bean)
{
$data = $bean->export();
$model = $bean->box() !== null ? $bean->box() : null;
if (!$model) {
throw new ModelValidation_Exception('This bean does not have a model!');
}
$rules = isset($model::$rules) ? $model::$rules : null;
if (!$rules) {
throw new ModelValidation_Exception('This bean does not have any established rules!');
}
$validations = [];
$filters = [];
$labels = [];
$messages = [];
foreach ($rules as $field => $rule) {
if (isset($rule['filter'])) {
$filters[$field] = $rule['filter'];
}
if (isset($rule['label'])) {
$labels[$field] = $rule['label'];
}
if (isset($rule['validation'])) {
$validations[$field] = $rule['validation'];
}
if (isset($rule['message'])) {
$field = isset($rule['label']) ? $rule['label'] : ucwords(str_replace(array('_', '-'), chr(32), $field));
$messages[$field] = $rule['message'];
}
}
$gump = new \GUMP();
if (!empty($filters)) {
$gump->filter_rules($filters);
}
if (!empty($validations)) {
$gump->validation_rules($validations);
}
if (!empty($labels)) {
$gump->set_field_names($labels);
}
$validated_data = $gump->run($data);
if ($validated_data === false) {
return self::default2custom_errors($gump->get_errors_array(), $messages);
} else {
$bean->import($validated_data);
return true;
}
}