remove Engine::init

v4
fadrian06 16 hours ago
parent 80be8eaeeb
commit 161bd9817c

@ -113,39 +113,7 @@ class Engine
{ {
$this->loader = new Loader(); $this->loader = new Loader();
$this->dispatcher = new Dispatcher(); $this->dispatcher = new Dispatcher();
$this->init();
}
/**
* @param string $name Method name
* @param array<int, mixed> $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 // Register default components
$this->loader->register('eventDispatcher', EventDispatcher::class); $this->loader->register('eventDispatcher', EventDispatcher::class);
$this->loader->register('request', Request::class); $this->loader->register('request', Request::class);
@ -174,6 +142,33 @@ class Engine
} }
} }
/**
* @param string $name Method name
* @param array<int, mixed> $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. * Custom error handler. Converts errors into exceptions.
* *

@ -16,7 +16,7 @@ class DocExamplesTest extends TestCase
{ {
$_SERVER = []; $_SERVER = [];
$_REQUEST = []; $_REQUEST = [];
Flight::init(); Flight::app();
Flight::setEngine(new Engine()); Flight::setEngine(new Engine());
} }

@ -15,7 +15,7 @@ class EventSystemTest extends TestCase
{ {
// Reset the Flight engine before each test to ensure a clean state // Reset the Flight engine before each test to ensure a clean state
Flight::setEngine(new Engine()); Flight::setEngine(new Engine());
Flight::app()->init(); Flight::app();
Flight::eventDispatcher()->resetInstance(); // Clear any existing listeners Flight::eventDispatcher()->resetInstance(); // Clear any existing listeners
} }

@ -20,7 +20,7 @@ class FlightTest extends TestCase
{ {
$_SERVER = []; $_SERVER = [];
$_REQUEST = []; $_REQUEST = [];
Flight::init(); Flight::app();
Flight::setEngine(new Engine()); Flight::setEngine(new Engine());
Flight::set('flight.views.path', __DIR__ . '/views'); Flight::set('flight.views.path', __DIR__ . '/views');
} }

@ -26,7 +26,7 @@ class RouteCommandTest extends TestCase
$_SERVER = []; $_SERVER = [];
$_REQUEST = []; $_REQUEST = [];
Flight::init(); Flight::app();
Flight::setEngine(new Engine()); Flight::setEngine(new Engine());
} }

Loading…
Cancel
Save