-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectPropertyValidator.php
More file actions
41 lines (37 loc) · 1.36 KB
/
Copy pathObjectPropertyValidator.php
File metadata and controls
41 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* @author: Jens Giessmann <jg@handcode.de>
*
* @copyright: 2026 - NOW(), Jens Giessmann
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace handcode\dynamicFormModel;
use yii\base\Model;
use yii\validators\Validator;
/**
* this Validator is used to validate DynamicFormModel properties of type 'object'
*/
class ObjectPropertyValidator extends Validator
{
public function validateAttribute($model, $attribute)
{
/** @var Model $model */
if (isset($model->{$attribute}) && $model->{$attribute} instanceof DynamicFormModel) {
if (!$model->{$attribute}->validate()) {
$this->addError($model, $attribute, 'The object property [{attributeName}] has errors.', ['attributeName' => $attribute]);
foreach ($model->{$attribute}->getErrors() as $key => $errors) {
if (is_string($errors)) {
$this->addError($model, $attribute, implode(' :: ', [$key, $errors]));
}
if (is_array($errors)) {
foreach ($errors as $errorMsg) {
$this->addError($model, $attribute, implode(' :: ', [$key, $errorMsg]));
}
}
}
}
}
}
}