Skip to content

Commit 61f0e6b

Browse files
committed
feat: move to a compiled architecture for v5
1 parent 3a0925f commit 61f0e6b

5 files changed

Lines changed: 171 additions & 89 deletions

File tree

‎LICENSE‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Michael Darko-Duodu
3+
Copyright (c) 2026 Michael Darko-Duodu
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎src/App.php‎

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function loadConfig(array $userSettings = [])
5050
{
5151
if (!empty($userSettings)) {
5252
Config::set(array_merge($userSettings, [
53-
'mode' => _env('APP_ENV', Config::getStatic('mode')),
53+
'mode' => _env('APP_ENV', $userSettings['mode'] ?? Config::getStatic('mode')),
5454
]));
5555
}
5656

@@ -93,6 +93,20 @@ public function register($name, $value)
9393

9494
private function setupDefaultContainer()
9595
{
96+
$mode = _env('APP_ENV', Config::getStatic('mode') ?: 'development');
97+
Config::set('mode', $mode);
98+
99+
if (Config::getStatic('debug') === null) {
100+
Config::set('debug', $mode !== 'production');
101+
}
102+
103+
$sessionCookie = Config::getStatic('session.cookie') ?? [];
104+
105+
if (($sessionCookie['secure'] ?? null) === null) {
106+
$sessionCookie['secure'] = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
107+
Config::set('session.cookie', $sessionCookie);
108+
}
109+
96110
Config::singleton('request', function () {
97111
return new Http\Request();
98112
});
@@ -108,8 +122,6 @@ private function setupDefaultContainer()
108122
Config::singleton('app', function () {
109123
return $this;
110124
});
111-
112-
Config::set('mode', _env('APP_ENV', Config::getStatic('mode')));
113125
}
114126

115127
public function __get($name)
@@ -240,22 +252,6 @@ public function csrf($options = [])
240252
});
241253
}
242254

243-
/**
244-
* Create a route handled by websocket (requires Eien module)
245-
*
246-
* @param string $name The url of the route
247-
* @param callable $callback The callback function
248-
* @uses package Eien module
249-
* @see https://leafphp.dev/modules/eien/
250-
*/
251-
public function ws(string $name, callable $callback)
252-
{
253-
Config::set('eien.events', \array_merge(
254-
Config::getStatic('eien.events') ?? [],
255-
[$name => $callback]
256-
));
257-
}
258-
259255
/********************************************************************************
260256
* Logging
261257
*******************************************************************************/
@@ -382,14 +378,6 @@ public static function environment($mode, $callback)
382378
*/
383379
public static function run(?callable $callback = null)
384380
{
385-
if (\class_exists('Leaf\Eien\Server') && Config::getStatic('eien.enabled')) {
386-
server()
387-
->wrap(function () use ($callback) {
388-
parent::run($callback);
389-
})
390-
->listen();
391-
} else {
392-
return parent::run($callback);
393-
}
381+
return parent::run($callback);
394382
}
395383
}

‎src/Config.php‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class Config
1818
protected static $context = [
1919
'app' => null,
2020
'app.down' => false,
21-
'debug' => true,
22-
'eien.enabled' => true,
21+
'debug' => null,
2322
'http.version' => '1.1',
2423
'log.writer' => null,
2524
'log.level' => null,
@@ -28,9 +27,9 @@ class Config
2827
'log.file' => 'app.log',
2928
'log.open' => true,
3029
'mode' => 'development',
31-
'session' => true,
30+
'session' => false,
3231
'session.lifetime' => 60 * 60 * 24,
33-
'session.cookie' => ['secure' => false, 'httponly' => true, 'samesite' => 'lax'],
32+
'session.cookie' => ['secure' => null, 'httponly' => true, 'samesite' => 'lax'],
3433
'scripts' => [],
3534
'views.path' => null,
3635
'views.cachePath' => null,
@@ -219,7 +218,6 @@ public static function reset()
219218
'app' => static::$context['app'],
220219
'app.down' => static::$context['app.down'],
221220
'debug' => static::$context['debug'],
222-
'eien.enabled' => static::$context['eien.enabled'],
223221
'http.version' => static::$context['http.version'],
224222
'log.writer' => static::$context['log.writer'],
225223
'log.level' => static::$context['log.level'],
@@ -228,6 +226,9 @@ public static function reset()
228226
'log.file' => static::$context['log.file'],
229227
'log.open' => static::$context['log.open'],
230228
'mode' => static::$context['mode'],
229+
'session' => static::$context['session'],
230+
'session.lifetime' => static::$context['session.lifetime'],
231+
'session.cookie' => static::$context['session.cookie'],
231232
'scripts' => [],
232233
'views.path' => static::$context['views.path'],
233234
'views.cachePath' => static::$context['views.cachePath'],

0 commit comments

Comments
 (0)