1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of product_management |
4
|
|
|
* User: Sinan TURGUT <[email protected]> |
5
|
|
|
* Date: 24.06.2019 |
6
|
|
|
* php version 7.2 |
7
|
|
|
* |
8
|
|
|
* @category Assessment |
9
|
|
|
* @package ProductManagement |
10
|
|
|
* @author Sinan TURGUT <[email protected]> |
11
|
|
|
* @license See LICENSE file |
12
|
|
|
* @link https://dev.sinanturgut.com.tr |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace App\Core; |
16
|
|
|
|
17
|
|
|
use Exception; |
18
|
|
|
use ReflectionClass; |
19
|
|
|
use ReflectionMethod; |
20
|
|
|
use App\Utility\Input; |
21
|
|
|
use App\Utility\Redirect; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class App |
25
|
|
|
* @package App\Core |
26
|
|
|
*/ |
27
|
|
|
class App |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $_class = INDEX_CONTROLLER; |
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $_method = INDEX_ACTION; |
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
private $_params = []; |
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $_pnf='pageNotFound'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* App constructor. |
49
|
|
|
*/ |
50
|
|
|
public function __construct() |
51
|
|
|
{ |
52
|
|
|
$this->parseURL(); |
53
|
|
|
try { |
54
|
|
|
$this->getClass(); |
55
|
|
|
$this->getMethod(); |
56
|
|
|
$this->getParams(); |
57
|
|
|
} catch (Exception $ex) { |
58
|
|
|
Redirect::to(404, $this->_pnf, Input::get("url")); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
*/ |
65
|
|
|
private function getClass() |
66
|
|
|
{ |
67
|
|
|
|
68
|
|
|
if (isset($this->_params[0]) && ! empty($this->_params[0])) { |
69
|
|
|
$this->_class = CONTROLLER_PATH . $this->_params[0]; |
70
|
|
|
unset($this->_params[0]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (!class_exists($this->_class)) { |
74
|
|
|
Redirect::to(404, $this->_pnf, Input::get("url")); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
$this->_class = new $this->_class; |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @throws \ReflectionException |
81
|
|
|
*/ |
82
|
|
|
private function getMethod() |
83
|
|
|
{ |
84
|
|
|
if (isset($this->_params[1]) && ! empty($this->_params[1])) { |
85
|
|
|
$this->_method = $this->_params[1]; |
86
|
|
|
unset($this->_params[1]); |
87
|
|
|
} |
88
|
|
|
if (!(new ReflectionClass($this->_class))->hasMethod($this->_method)) { |
89
|
|
|
Redirect::to(404, $this->_pnf, Input::get("url")); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
if (!(new ReflectionMethod($this->_class, $this->_method))->isPublic()) { |
92
|
|
|
Redirect::to(404, $this->_pnf, Input::get("url")); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* |
98
|
|
|
*/ |
99
|
|
|
private function getParams() |
100
|
|
|
{ |
101
|
|
|
$this->_params = $this->_params ? array_values($this->_params) : []; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* |
106
|
|
|
*/ |
107
|
|
|
private function parseURL() |
108
|
|
|
{ |
109
|
|
|
if ($url = Input::get("url")) { |
110
|
|
|
$this->_params = explode("/", filter_var(rtrim($url, "/"), FILTER_SANITIZE_URL)); |
111
|
|
|
$this->_params=array_slice($this->_params, 1); |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* |
118
|
|
|
*/ |
119
|
|
|
public function run() |
120
|
|
|
{ |
121
|
|
|
call_user_func_array([$this->_class, $this->_method], $this->_params); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|