@@ -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}
0 commit comments