1 | <?php |
||
15 | class TranslitValidator extends Validator |
||
16 | { |
||
17 | /** |
||
18 | * Override default behavior of validator - do not skip empty values. |
||
19 | * |
||
20 | * @var boolean |
||
21 | */ |
||
22 | public $skipOnEmpty = false; |
||
23 | |||
24 | /** |
||
25 | * Name of attribute which value will be transliterated. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | public $sourceAttribute; |
||
30 | |||
31 | /** |
||
32 | * Whether to lower case transliterated string. |
||
33 | * |
||
34 | * @var boolean |
||
35 | */ |
||
36 | public $lowercase = true; |
||
37 | |||
38 | /** |
||
39 | * Whether to prepare transliterated string for URL. |
||
40 | * |
||
41 | * If set to true, all invalid characters matched by $invalidRegexp will be |
||
42 | * replaced with $invalidReplacement string. |
||
43 | * |
||
44 | * @var boolean |
||
45 | */ |
||
46 | public $forUrl = true; |
||
47 | |||
48 | /** |
||
49 | * Regular expression that matched invalid characters for URL. |
||
50 | * |
||
51 | * By default matches all non-alphanumeric symbols. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | public $invalidRegexp = '/[^a-z0-9]+/i'; |
||
56 | |||
57 | /** |
||
58 | * String with which all invalid characters will be replaced. |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | public $invalidReplacement = '-'; |
||
63 | |||
64 | /** |
||
65 | * Trim invalid characters at beginning and at end of given string. |
||
66 | * |
||
67 | * @var boolean |
||
68 | */ |
||
69 | public $trimInvalid = false; |
||
70 | |||
71 | /** |
||
72 | * Cached escaped invalid replacement. |
||
73 | * |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $escapedInvalidReplacement = null; |
||
77 | |||
78 | /** |
||
79 | * Escape invalid replacement string. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | protected function getEscapedInvalidReplacement() |
||
91 | |||
92 | /** |
||
93 | * Prepare string for URL. |
||
94 | * |
||
95 | * @param string $value |
||
96 | * @return string |
||
97 | */ |
||
98 | protected function prepareForUrl($value) |
||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | public function validateAttribute($model, $attribute) |
||
151 | } |
||
152 |