Completed
Push — master ( 24c4aa...872463 )
by Ivannis Suárez
02:16
created

Assert::registerValidator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cubiche\Core\Validator;
12
13
use Respect\Validation\Validator as Constraints;
14
15
/**
16
 * Assert class.
17
 *
18
 * @author Ivannis Suárez Jerez <[email protected]>
19
 */
20
class Assert extends Constraints
21
{
22
    /**
23
     * @var array
24
     */
25
    protected static $namespaces = array();
26
27
    /**
28
     * @var string
29
     */
30
    const DEFAULT_GROUP = 'Default';
31
32
    /**
33
     * Create a constraints instance.
34
     *
35
     * @return Constraints
36
     */
37
    public static function create()
38
    {
39
        return new static(func_get_args());
40
    }
41
42
    /**
43
     * @param string $namespace
44
     * @param bool   $prepend
45
     */
46
    public static function registerValidator($namespace, $prepend = false)
47
    {
48
        if (!isset(static::$namespaces[$namespace])) {
49
            static::$namespaces[$namespace] = $prepend;
50
        }
51
    }
52
53
    /**
54
     * @param string $ruleName
55
     * @param array  $arguments
56
     *
57
     * @return Validator
58
     */
59
    public static function __callStatic($ruleName, $arguments)
60
    {
61
        foreach (static::$namespaces as $namespace => $prepend) {
62
            static::with($namespace, $prepend);
63
        }
64
65
        return parent::__callStatic($ruleName, $arguments);
66
    }
67
}
68