Passed
Push — master ( 63f321...eeb79a )
by Henri
01:21
created

Helper::import()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace HnrAzevedo\Router;
4
5
use HnrAzevedo\Validator\Validator;
6
7
trait Helper{
8
    use CheckTrait;
9
    
10
    protected function getProtocol(): string
11
    {
12
        if((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')){
13
            return 'ajax';
14
        }
15
        
16
        /* ONLY FOR DEBUG CONDITION */
17
        if(!array_key_exists('REQUEST_METHOD',$_SERVER)){
18
            return 'get';
19
        }
20
21
        return strtolower($_SERVER['REQUEST_METHOD']);
22
    }
23
24
    protected function getData(): ?array
25
    {
26
        return [
27
            'POST' => $_POST,
28
            'GET' => $_GET,
29
            'FILES' => $_FILES
30
        ];
31
    }
32
33
    protected function import(string $path)
34
    {
35
        foreach (scandir($path) as $routeFile) {
36
            if(pathinfo($path.DIRECTORY_SEPARATOR.$routeFile, PATHINFO_EXTENSION) === 'php'){
37
                require_once($path. DIRECTORY_SEPARATOR .$routeFile);
38
            }
39
        }
40
    }
41
42
    protected function ControllerForm($controller, string $method, array $values){
43
		if(Validator::execute($values)){
44
45
            $this->check_role();
46
47
            $role = ($method !== 'method') ? $method : $this->getData()['POST']['role'];
48
            $data = (!is_null($values)) ? json_decode($values['data']) : null;
0 ignored issues
show
introduced by
The condition is_null($values) is always false.
Loading history...
49
            $controller->$role($data);
50
        }
51
    }
52
53
}