1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Win; |
4
|
|
|
|
5
|
|
|
use App\Controllers\IndexController; |
6
|
|
|
use Win\Controllers\Controller; |
7
|
|
|
use Win\Repositories\Database\Connection; |
8
|
|
|
use Win\Request\Router; |
9
|
|
|
use Win\Request\Url; |
10
|
|
|
use Win\HttpException; |
11
|
|
|
use Win\Views\View; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Application (WinPHP Framework) |
15
|
|
|
* |
16
|
|
|
* Framework em PHP baseado em MVC |
17
|
|
|
* Responsável por incluir as páginas de acordo com a URL e criar a estrutura MVC |
18
|
|
|
* @author winPHP Framework <http://github.com/winframework/winphp/> |
19
|
|
|
* @version 1.5.1 |
20
|
|
|
*/ |
21
|
|
|
class Application |
22
|
|
|
{ |
23
|
|
|
/** @var Controller */ |
24
|
|
|
public $controller; |
25
|
|
|
|
26
|
|
|
/** @var View */ |
27
|
|
|
public $view; |
28
|
|
|
|
29
|
|
|
/** @var Connection */ |
30
|
|
|
public $conn; |
31
|
|
|
|
32
|
|
|
/** @var static */ |
33
|
|
|
protected static $instance; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Cria a aplicação principal |
37
|
|
|
*/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
static::$instance = $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Retorna o ponteiro para a aplicação principal |
45
|
|
|
* @return static |
46
|
|
|
*/ |
47
|
|
|
public static function app() |
48
|
|
|
{ |
49
|
|
|
return static::$instance; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Roda a aplicação e envia a resposta |
54
|
|
|
*/ |
55
|
|
|
public function run() |
56
|
|
|
{ |
57
|
|
|
Router::process(Router::getDestination()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** @return string */ |
61
|
|
|
public function getFullUrl() |
62
|
|
|
{ |
63
|
|
|
return Url::instance()->getBaseUrl() . Url::instance()->getUrl(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @return string */ |
67
|
|
|
public function getBaseUrl() |
68
|
|
|
{ |
69
|
|
|
return Url::instance()->getBaseUrl(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Retorna a URL Atual |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getUrl() |
77
|
|
|
{ |
78
|
|
|
return Url::instance()->getUrl(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Retorna a página atual |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getPage() |
86
|
|
|
{ |
87
|
|
|
return Url::instance()->getSegments()[0]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Retorna TRUE se está na página inicial |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
|
|
public function isHomePage() |
95
|
|
|
{ |
96
|
|
|
return $this->controller instanceof IndexController; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Define a página como 404 |
101
|
|
|
* @param string $message |
102
|
|
|
* @throws HttpException |
103
|
|
|
*/ |
104
|
|
|
public function page404($message = '') |
105
|
|
|
{ |
106
|
|
|
throw new HttpException($message, 404); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Define a página atual como algum erro |
111
|
|
|
* @param int $code |
112
|
|
|
* @param string $message |
113
|
|
|
* @throws HttpException |
114
|
|
|
*/ |
115
|
|
|
public function errorPage($code, $message = '') |
116
|
|
|
{ |
117
|
|
|
throw new HttpException($message, $code); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|