|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This software package is licensed under AGPL or Commercial license. |
|
5
|
|
|
* |
|
6
|
|
|
* @package maslosoft/mangan |
|
7
|
|
|
* @licence AGPL or Commercial |
|
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) Maslosoft |
|
10
|
|
|
* @copyright Copyright (c) Others as mentioned in code |
|
11
|
|
|
* @link http://maslosoft.com/mangan/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Annotations\Validators; |
|
15
|
|
|
|
|
16
|
|
|
use Maslosoft\Addendum\Helpers\ParamsExpander; |
|
17
|
|
|
use Maslosoft\Mangan\Meta\ValidatorMeta; |
|
18
|
|
|
use Maslosoft\Mangan\Validators\Proxy\UniqueProxy; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* UniqueValidator |
|
22
|
|
|
* |
|
23
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
24
|
|
|
*/ |
|
25
|
|
|
class UniqueValidatorAnnotation extends ValidatorAnnotation |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
use \Maslosoft\Mangan\Validators\Traits\AllowEmpty; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string the ActiveRecord class name that should be used to |
|
32
|
|
|
* look for the attribute value being validated. Defaults to null, meaning using |
|
33
|
|
|
* the class of the object currently being validated. |
|
34
|
|
|
* You may use path alias to reference a class name here. |
|
35
|
|
|
* @see attributeName |
|
36
|
|
|
* @since 1.0.8 |
|
37
|
|
|
*/ |
|
38
|
|
|
public $className; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string the ActiveRecord class attribute name that should be |
|
42
|
|
|
* used to look for the attribute value being validated. Defaults to null, |
|
43
|
|
|
* meaning using the name of the attribute being validated. |
|
44
|
|
|
* @see className |
|
45
|
|
|
* @since 1.0.8 |
|
46
|
|
|
*/ |
|
47
|
|
|
public $attributeName; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var array additional query criteria. This will be combined with the condition |
|
51
|
|
|
* that checks if the attribute value exists in the corresponding table column. |
|
52
|
|
|
* This array will be used to instantiate a {@link CDbCriteria} object. |
|
53
|
|
|
* @since 1.0.8 |
|
54
|
|
|
*/ |
|
55
|
|
|
public $criteria = []; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string the user-defined error message. The placeholders "{attribute}" and "{value}" |
|
59
|
|
|
* are recognized, which will be replaced with the actual attribute name and value, respectively. |
|
60
|
|
|
*/ |
|
61
|
|
|
public $message; |
|
62
|
|
|
|
|
63
|
|
|
public function init() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->proxy = UniqueProxy::class; |
|
66
|
|
|
$this->_entity->validators[] = new ValidatorMeta(ParamsExpander::expand($this, [ |
|
67
|
|
|
'allowEmpty', |
|
68
|
|
|
'className', |
|
69
|
|
|
'attributeName', |
|
70
|
|
|
'criteria', |
|
71
|
|
|
'message', |
|
72
|
|
|
'skipOnError', |
|
73
|
|
|
'on', |
|
74
|
|
|
'safe', |
|
75
|
|
|
'enableClientValidation', |
|
76
|
|
|
'except', |
|
77
|
|
|
'proxy' |
|
78
|
|
|
])); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|