ValidatorDispatcher::initRule()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
1
<?php
2
namespace JayaCode\Framework\Core\Validator\Dispatcher;
3
4
/**
5
 * Class ValidatorDispatcher
6
 * @package JayaCode\Framework\Core\Validator\Dispatcher
7
 */
8
abstract class ValidatorDispatcher
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $rules = [];
14
    /**
15
     * @var array
16
     */
17
    protected $errorMessage = [];
18
    /**
19
     * @var array
20
     */
21
    protected $namespaceClassRule = [
22
            'App\\Validator\\Rule\\',
23
            'JayaCode\\Framework\\Core\\Validator\\Rule\\'
24
    ];
25
26
    /**
27
     * ValidatorDispatcher constructor.
28
     * @param array $rules
29
     * @param array $namespace
30
     */
31 12
    public function __construct(array $rules, array $namespace = null)
32
    {
33 12
        $this->initRule($rules);
34
35 12
        if (is_array($namespace)) {
36
            foreach ($this->namespaceClassRule as $item) {
37
                array_push($namespace, $item);
38
            }
39
40
            $this->namespaceClassRule = $namespace;
41
        }
42 12
    }
43
44
45
    /**
46
     * @param array $data
47
     * @return mixed
48
     */
49
    abstract public function isValid($data = []);
50
51
    /**
52
     * @return array
53
     */
54 12
    public function getErrorMessage()
55
    {
56 12
        return $this->errorMessage;
57
    }
58
59
    /**
60
     * @param array $rules
61
     */
62
    abstract public function initRule(array $rules);
63
64
    /**
65
     * @param $attributesString
66
     * @param $nameData
67
     * @return mixed
68
     */
69
    abstract protected function getObjectRule($attributesString, $nameData);
70
}
71