|
|
|
|
@ -113,39 +113,7 @@ class Engine
|
|
|
|
|
{
|
|
|
|
|
$this->loader = new Loader();
|
|
|
|
|
$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
|
|
|
|
|
$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<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.
|
|
|
|
|
*
|
|
|
|
|
|