protected function serve(array $route, array $args = [])
{
static $calledOnce = null;
if (count($route) === 1) {
$route[] = 'index';
}
try {
$class_name = Gears::getName('Landing__' . $route[0]);
} catch (GearNotFound $ex) {
$class_name = '\\Airship\\Cabin\\' . self::$active_cabin . '\\Landing\\' . $route[0];
}
$method = $route[1];
if (!\class_exists($class_name)) {
$state = State::instance();
$state->logger->error('Landing Error: Class not found when invoked from router', ['route' => ['class' => $class_name, 'method' => $method]]);
$calledOnce = true;
return $this->serveFallback();
}
// Load our cabin-specific landing
$landing = new $class_name();
if (!$landing instanceof Landing) {
throw new \Error(\__("%s is not a Landing", "default", $class_name));
}
// Dependency injection with a twist
$landing->airshipEjectFromCockpit($this->lens, $this->databases, self::$patternPrefix);
// Tighten the Bolts!
\Airship\tightenBolts($landing);
if (!\method_exists($landing, $method)) {
if ($calledOnce) {
throw new FallbackLoop(\trk('errors.router.fallback_loop'));
}
$calledOnce = true;
return $this->serveFallback();
}
return $landing->{$method}(...$args);
}