/
Core.php
79 lines (65 loc) · 1.63 KB
/
Core.php
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class Core extends \Slim\Slim
{
public static $instance;
private $arHelpers = array();
function __construct($args = array()) {
\Slim\Slim::__construct($args);
self::$instance = $this;
}
public static function coreInstance() {
if (!isset(self::$instance))
{
$object = __CLASS__;
self::$instance = new $object;
}
return self::$instance;
}
public function loadLibrary($name) {
if (file_exists(FOLDER_LIBS . "/" . $name . ".php"))
require_once FOLDER_LIBS . "/" . $name . ".php";
}
public function loadModel($name, $key = false) {
require_once FOLDER_MODELS . '/' . $name . ".php";
if ($key) {
$name = "\\models\\" . $name;
$this->$key = new $name();
}
}
public function loadHelper($name, $key = false) {
if (array_search($name, $this->arHelpers) === false) {
require_once FOLDER_HELPERS . '/' . $name . '.php';
array_push($this->arHelpers, $name);
if ($key) {
$name = "\\helpers\\" . $name;
$this->$key = new $name();
}
}
}
public function getPosts($args = false) {
if ($args) {
$post = $this->request->post();
foreach ($args as $arg) {
if (!isset($post[$arg])) {
return false;
}
}
}
return $this->request->post();
}
public function getHeaders($dat) {
if ($dat != "")
return $this->request->headers->get($dat);
return $this->request->headers;
}
public function render($template, $data = array(), $status = null) {
//error_reporting(E_ALL & ~E_NOTICE);
$data["app"] = $this;
\Slim\Slim::render($template, $data);
}
public function redirect($url, $status = 302) {
$url = BASE_URL . $url;
\Slim\Slim::redirect($url, $status);
}
}
?>