Completed
Branch master (a1edd4)
by
unknown
54:09
created

UrlPathValidator::validateAttribute()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 2
1
<?php
2
/**
3
 * This file is part of the fangface/yii2-concord package
4
 *
5
 * For the full copyright and license information, please view
6
 * the file LICENSE.md that was distributed with this source code.
7
 *
8
 * @package fangface/yii2-concord
9
 * @author Fangface <[email protected]>
10
 * @copyright Copyright (c) 2014 Fangface <[email protected]>
11
 * @license https://github.com/fangface/yii2-concord/blob/master/LICENSE.md MIT License
12
 *
13
 */
14
15
namespace fangface\validators;
16
17
use fangface\validators\AlphaValidator;
18
19
/**
20
 * AlphaValidator validates that the attribute value is a alpha/alphanumeric string.
21
 *
22
 * @author Nicola Puddu (based on yii1 version at http://www.yiiframework.com/extension/alpha/)
23
 * @author Fangface
24
 */
25
class UrlPathValidator extends AlphaValidator
26
{
27
    /**
28
     * @var int maximum number of characters to validate the string
29
     */
30
    public $maxChars = 255;
31
    /**
32
     * @var boolean
33
     */
34
    public $allowNumbers = true;
35
    /**
36
     * @var boolean
37
     */
38
    public $allowMinus = true;
39
    /**
40
     * @var boolean
41
     */
42
    public $allowUnderscore = true;
43
    /**
44
     * @var boolean
45
     */
46
    public $allowDot = true;
47
    /**
48
     * @var boolean first character of string must be forward slash
49
     */
50
    public $forceChar1Slash = true;
51
    /**
52
     * @var array list of additional characters allowed
53
     */
54
    public $extra = array('/');
55
56
57
    /**
58
     * @inheritdoc
59
     */
60
    public function validateAttribute($object, $attribute)
61
    {
62
        /* @var \yii\base\Model $object */
63
        // validate the string
64
        $value = $object->$attribute;
65
        if ($this->skipOnEmpty && empty($value)) {
66
            return;
67
        }
68
69
        parent::validateAttribute($object, $attribute);
70
71
        if ($object->hasErrors($attribute)) {
72
            return;
73
        }
74
    }
75
}
76