From 161bd9817c663e25d2fd6c96b9106e11f70e62b2 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Wed, 1 Apr 2026 13:07:55 -0400 Subject: [PATCH] remove Engine::init --- src/Engine.php | 59 +++++++++++++---------------- tests/DocExamplesTest.php | 2 +- tests/EventSystemTest.php | 2 +- tests/FlightTest.php | 2 +- tests/commands/RouteCommandTest.php | 2 +- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/Engine.php b/src/Engine.php index 9e99cdc..6557342 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -113,39 +113,7 @@ class Engine { $this->loader = new Loader(); $this->dispatcher = new Dispatcher(); - $this->init(); - } - - /** - * @param string $name Method name - * @param array $arguments Method parameters - * @throws Throwable - * @return mixed - */ - public function __call(string $name, array $arguments) - { - $callback = $this->dispatcher->get($name); - - if (is_callable($callback)) { - return $this->dispatcher->run($name, $arguments); - } - - if (!$this->loader->get($name)) { - throw new Exception("$name must be a mapped method."); - } - - $shared = empty($arguments) || $arguments[0]; - - return $this->loader->load($name, $shared); - } - - ////////////////// - // Core Methods // - ////////////////// - /** Initializes the framework */ - public function init(): void - { // Register default components $this->loader->register('eventDispatcher', EventDispatcher::class); $this->loader->register('request', Request::class); @@ -174,6 +142,33 @@ class Engine } } + /** + * @param string $name Method name + * @param array $arguments Method parameters + * @throws Throwable + * @return mixed + */ + public function __call(string $name, array $arguments) + { + $callback = $this->dispatcher->get($name); + + if (is_callable($callback)) { + return $this->dispatcher->run($name, $arguments); + } + + if (!$this->loader->get($name)) { + throw new Exception("$name must be a mapped method."); + } + + $shared = empty($arguments) || $arguments[0]; + + return $this->loader->load($name, $shared); + } + + ////////////////// + // Core Methods // + ////////////////// + /** * Custom error handler. Converts errors into exceptions. * diff --git a/tests/DocExamplesTest.php b/tests/DocExamplesTest.php index 0bdacb0..c3ac378 100644 --- a/tests/DocExamplesTest.php +++ b/tests/DocExamplesTest.php @@ -16,7 +16,7 @@ class DocExamplesTest extends TestCase { $_SERVER = []; $_REQUEST = []; - Flight::init(); + Flight::app(); Flight::setEngine(new Engine()); } diff --git a/tests/EventSystemTest.php b/tests/EventSystemTest.php index 9a229b6..4126289 100644 --- a/tests/EventSystemTest.php +++ b/tests/EventSystemTest.php @@ -15,7 +15,7 @@ class EventSystemTest extends TestCase { // Reset the Flight engine before each test to ensure a clean state Flight::setEngine(new Engine()); - Flight::app()->init(); + Flight::app(); Flight::eventDispatcher()->resetInstance(); // Clear any existing listeners } diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 7c9d60f..b407f70 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -20,7 +20,7 @@ class FlightTest extends TestCase { $_SERVER = []; $_REQUEST = []; - Flight::init(); + Flight::app(); Flight::setEngine(new Engine()); Flight::set('flight.views.path', __DIR__ . '/views'); } diff --git a/tests/commands/RouteCommandTest.php b/tests/commands/RouteCommandTest.php index 3aea0b1..5cea39d 100644 --- a/tests/commands/RouteCommandTest.php +++ b/tests/commands/RouteCommandTest.php @@ -26,7 +26,7 @@ class RouteCommandTest extends TestCase $_SERVER = []; $_REQUEST = []; - Flight::init(); + Flight::app(); Flight::setEngine(new Engine()); }