From ca7b5b47b9f18a550a95aac91a28027a0f1fd530 Mon Sep 17 00:00:00 2001 From: Joan Miquel Date: Fri, 14 Feb 2025 15:42:39 +0100 Subject: [PATCH 1/2] Simplify Flight and faster performance Null coalescing operator work from PHP 7.0 --- flight/Flight.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/flight/Flight.php b/flight/Flight.php index 8887269..1d38677 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -87,9 +87,6 @@ class Flight /** Framework engine. */ private static Engine $engine; - /** Whether or not the app has been initialized. */ - private static bool $initialized = false; - /** * Don't allow object instantiation * @@ -127,14 +124,7 @@ class Flight /** @return Engine Application instance */ public static function app(): Engine { - if (!self::$initialized) { - require_once __DIR__ . '/autoload.php'; - - self::setEngine(new Engine()); - self::$initialized = true; - } - - return self::$engine; + return self::$engine ?? self::$engine = new Engine(); } /** @@ -142,8 +132,8 @@ class Flight * * @param Engine $engine Vroom vroom! */ - public static function setEngine(Engine $engine): void + public static function setEngine(Engine $engine): Engine { - self::$engine = $engine; + return self::$engine = $engine; } } From 78e3a5ed6aa4b0f1f4d1d5a29ee9dba8f652e69d Mon Sep 17 00:00:00 2001 From: Joan Miquel Date: Fri, 14 Feb 2025 15:59:26 +0100 Subject: [PATCH 2/2] Revert setEngine() --- flight/Flight.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flight/Flight.php b/flight/Flight.php index 1d38677..59a9945 100644 --- a/flight/Flight.php +++ b/flight/Flight.php @@ -132,8 +132,8 @@ class Flight * * @param Engine $engine Vroom vroom! */ - public static function setEngine(Engine $engine): Engine + public static function setEngine(Engine $engine): void { - return self::$engine = $engine; + self::$engine = $engine; } }