Repository navigation
Expand file tree
/
Copy pathKernel.php
More file actions
58 lines (47 loc) · 1.62 KB
/
Copy pathKernel.php
File metadata and controls
58 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class Core
{
// if aren't controller Pages will be loaded.
protected $currentController = 'Pages';
// Method 'index will be loaded in 'Pages'
protected $currentMethod = 'index';
protected $params = [];
public function __construct()
{
//// print_r($this->getUrl());
$url = $this->getUrl();
// look in 'controller' and capitalize first letter.
if (file_exists('../app/controller/' . ucwords($url[0]) . '.php')) {
$this->currentController = ucwords($url[0]);
// Unset 0 Index
unset($url[0]);
}
// Require the controller
require_once '../app/controller/' . $this->currentController . '.php';
$this->currentController = new $this->currentController;
// check for the second part of the Url.
if (isset($url[1])) {
if (method_exists($this->currentController, $url[1])) {
$this->currentMethod = $url[1];
unset($url[1]);
}
}
// Get parameters
$this->params = $url ? array_values($url) : [];
// Callback with params array
call_user_func_array([$this->currentController, $this->currentMethod], $this->params);
}
// get browser Url.
public function getUrl()
{
if (isset($_GET['url'])) {
// trim '/'.
$url = rtrim($_GET['url'], '/');
// removes all illegal URL characters.
$url = filter_var($url, FILTER_SANITIZE_URL);
// breaking Url into array.
$url = explode('/', $url);
return $url;
}
}
}