/
render.php
93 lines (78 loc) · 2.48 KB
/
render.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**********************************************************
* Lidiun PHP Framework 6.0 - (http://www.lidiun.com)
*
* @Created in 26/08/2013
* @Author Dyon Enedi <dyonenedi@hotmail.com>
* @By Dyon Enedi <dyonenedi@hotmail.com>
* @Contributor Gabriela A. Ayres Garcia <gabriela.ayres.garcia@gmail.com>
* @License: free
*
**********************************************************/
namespace Lidiun_Framework_v6;
class Render
{
private static $_reply = [];
public static function load() {
// Run Global Render
self::runGlobalRende();
// Run Controller
self::runController();
// Database close conection
Database::close();
// Delivery response
self::deliveryResponse();
}
private static function runGlobalRende(){
if (file_exists(Path::$_path['controller'] . 'global_controller.php')) {
Autoload::includePath('mvc'. SEPARATOR .'controller');
$globalController = 'global_controller';
$globalController = new $globalController;
$globalcontroller = null;
}
}
private static function runController(){
$isAjax = Request::isAjax();
if ($isAjax) {
Autoload::includePath('mvc' . SEPARATOR . 'controller' . SEPARATOR . 'ajax');
} else {
Autoload::includePath('mvc' . SEPARATOR . 'controller' . SEPARATOR . 'web');
}
Layout::loadContent();
$controller = Request::getController();
$controller .= '_controller';
if (class_exists($controller)) {
$app = new $controller;
} else {
Request::redirect('notfound');
}
$app = null;
}
private static function deliveryResponse(){
$isAjax = Request::isAjax();
if ($isAjax) {
if (empty(self::$_reply) || !is_array(self::$_reply)) {
exit('No reply seted by ajax controller or reply is not an array');
}
foreach (self::$_reply as $key => $value) {
if ($key != 'reply' && !is_numeric($value) && !is_array($value) && $value) {
self::$_reply[$key] = Language::translation($value);
}
}
Request::responseHeader();
echo json_encode(self::$_reply);
} else {
Layout::MenuFooterAutoload();
Layout::replaceTag();
Layout::translation();
Request::responseHeader();
echo Layout::getLayout();
}
}
##########################################################################
############################ PUBLIC METHODS ##############################
##########################################################################
public static function setReply($reply){
self::$_reply = $reply;
}
}