-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.php
More file actions
115 lines (100 loc) · 2.15 KB
/
App.php
File metadata and controls
115 lines (100 loc) · 2.15 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
110
111
112
113
114
115
<?php
/**
* @author : Jakiboy
* @package : FloatPHP Skeleton App
* @version : 1.5.x
* @copyright : (c) 2017 - 2025 Jihad Sinnaour <me@jihadsinnaour.com>
* @link : https://floatphp.com
* @license : MIT
*
* This file if a part of FloatPHP Framework.
*/
namespace App;
use FloatPHP\Kernel\Core;
use FloatPHP\Classes\Filesystem\Stringify;
use FloatPHP\Helpers\Framework\Debugger;
final class App
{
/**
* @access private
* @var bool $initialized
*/
private static $initialized = false;
/**
* Register app autoloader.
*
* @access private
*/
private function __construct()
{
global $__APP__;
$__APP__ = __DIR__;
// Include dependencies
if ( !file_exists($autoload = "{$__APP__}/vendor/autoload.php") ) {
exit(__CLASS__ . ': Autoload required');
}
require_once $autoload;
spl_autoload_register(callback: [__CLASS__, 'autoload']);
// Finish initialization
static::$initialized = true;
}
/**
* Unregister app autoloader.
*/
public function __destruct()
{
spl_autoload_unregister(callback: [__CLASS__, 'autoload']);
}
/**
* Autoloader method.
*
* @access private
* @param string $class
* @return void
*/
private function autoload(string $class) : void
{
$namespace = __NAMESPACE__;
if ( strpos(haystack: $class, needle: "{$namespace}\\") === 0 ) {
$class = Stringify::remove(string: "{$namespace}\\", subject: $class);
$class = Stringify::replace(search: '\\', replace: '/', subject: $class);
$namespace = Stringify::replace(
search: ['\\', '_'],
replace: ['/', '-'],
subject: $namespace
);
$class = Stringify::formatPath(
path: "{$namespace}/{$class}.php"
);
require_once $class;
}
}
/**
* Initialize framework.
*
* @access public
* @return void
*/
public static function init() : void
{
if ( !static::$initialized ) {
new static;
}
}
/**
* Start framework core.
*
* @access public
* @param array $config
* @return void
*/
public static function start(array $config = []) : void
{
if ( !static::$initialized ) {
self::init();
Debugger::init();
new Core($config);
Debugger::setExecutionTime();
}
}
}