Airship\Engine\Gears::getName PHP Method

getName() public static method

Get the class name of a Gear
public static getName ( string $name ) : string
$name string
return string
    public static function getName(string $name)
    {
        $state = State::instance();
        if (!isset($state->gears[$name])) {
            throw new GearNotFound($name);
        }
        $gears = $state->gears;
        return $gears[$name];
    }

Usage Example

Example #1
0
 /**
  * Actually serve the routes. Called by route() above.
  *
  * @param array $route
  * @param array $args
  * @return mixed
  * @throws FallbackLoop
  * @throws \Error
  */
 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);
 }
All Usage Examples Of Airship\Engine\Gears::getName