-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.php
More file actions
executable file
·109 lines (98 loc) · 2.69 KB
/
App.php
File metadata and controls
executable file
·109 lines (98 loc) · 2.69 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Pet;
use Pet\Errors\AppException;
use Pet\Errors\Errors;
use Pet\Request\Request;
use Pet\Router\Router;
use Pet\Session\Session;
use Pet\Tools\Tools;
class App
{
public const PUBLIC_DIR = PUBLIC_DIR;
public const ROUTER_DIR = ROUTER_DIR;
public $router;
public $request;
public $session;
public function __construct()
{
(new Errors());
self::isHtaccess();
$this->session = new Session();
$this->request = new Request();
$this->router = new Router();
}
/**
* init
*
* @return void
*/
public static function init()
{
$GLOBALS['app'] = new App();
self::initClass();
self::initRouter(self::ROUTER_DIR);
Router::init();
}
/**
* isHtaccess
*
* @return void
*/
private static function isHtaccess(): void
{
if (!file_exists(self::PUBLIC_DIR . '/.htaccess')) {
throw new AppException("Not file .htaccess", E_ERROR);
}
}
/**
* initRouter
* Запуск Роутеров
* @param mixed $path
* @return void
*/
public static function initRouter(string $path): void
{
if (!is_dir($path)) {
throw new AppException("Not Folder router", E_ERROR);
}
Tools::scan($path, function ($dir, $file) {
if (!empty($file) && pathinfo($file, PATHINFO_EXTENSION) === 'php'){
include_once($file);
}
if (!empty($dir)) {
self::initRouter($dir);
}
}, true);
}
/**
* initClass
* Запуск класоов проекта
* @return void
*/
public static function initClass()
{
spl_autoload_register(function ($class) {
$file = str_replace('\\', DS, $class) . '.php';
$file = self::PUBLIC_DIR.DS.$file;
if (file_exists($file)) {
require_once $file;
return true;
}
return false;
});
//Export external
if (defined('EXTERNAL_MODULE')) {
spl_autoload_register(function ($class) {
foreach (explode("||", EXTERNAL_MODULE) as $module) {
$path = ROOT . DS . "$module". DS;
$file = $path.str_replace('\\', DS, $class) . '.php';
if (file_exists($file)) {
require_once $file;
return true;
}
return false;
}
});
}
}
}