The gears class contains a bunch of methods for the plugin system (Airship Gears)
Beispiel #1
0
<?php

declare (strict_types=1);
use Airship\Engine\Gears;
/**
 * Let's gearify the current cabin:
 *
 * e.g. Landing__IndexPage => \Airship\Cabin\Hull\Landing\IndexPage
 *
 */
$cabinGearsClosure = function () {
    foreach (['Landing', 'Blueprint'] as $dir) {
        foreach (\glob(CABIN_DIR . '/' . $dir . '/*.php') as $landing) {
            $filename = \Airship\path_to_filename($landing, true);
            if ($filename === 'init_gear') {
                continue;
            }
            Gears::lazyForge($dir . '__' . $filename, '\\Airship\\Cabin\\' . CABIN_NAME . '\\' . $dir . '\\' . $filename);
        }
    }
};
$cabinGearsClosure();
unset($cabinGearsClosure);
Beispiel #2
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);
 }
Beispiel #3
0
<?php

declare (strict_types=1);
/**
 * Initialize the base types for our framework gears
 */
\Airship\Engine\Gears::init(['AirBrake' => '\\Airship\\Engine\\Security\\AirBrake', 'AutoPilot' => '\\Airship\\Engine\\AutoPilot', 'AutoUpdater' => '\\Airship\\Engine\\Continuum', 'Authentication' => '\\Airship\\Engine\\Security\\Authentication', 'Blueprint' => '\\Airship\\Engine\\Blueprint', 'Database' => '\\Airship\\Engine\\Database', 'CSRF' => '\\Airship\\Engine\\Security\\CSRF', 'Hail' => '\\Airship\\Engine\\Hail', 'Landing' => '\\Airship\\Engine\\Landing', 'Ledger' => '\\Airship\\Engine\\Ledger', 'Lens' => '\\Airship\\Engine\\Lens', 'Permissions' => '\\Airship\\Engine\\Security\\Permissions', 'Translation' => '\\Airship\\Engine\\Translation', 'TreeUpdater' => '\\Airship\\Engine\\Keyggdrasil']);
Beispiel #4
0
<?php

declare (strict_types=1);
namespace Airship\Cabin\Hull\Blueprint;

use Airship\Engine\Blueprint;
use Airship\Engine\Gears;
if (!\class_exists('BlueprintGear')) {
    Gears::extract('Blueprint', 'BlueprintGear', __NAMESPACE__);
    // Make autocomplete work with existing IDEs:
    if (IDE_HACKS) {
        /**
         * Class BlueprintGear
         * @package Airship\Cabin\Hull\Blueprint
         */
        class BlueprintGear extends Blueprint
        {
        }
    }
}
Beispiel #5
0
 /**
  * Grab a blueprint
  *
  * @param string $name
  * @param mixed[] ...$cArgs Constructor arguments
  * @return Blueprint
  * @throws InvalidType
  */
 protected function blueprint(string $name, ...$cArgs) : Blueprint
 {
     if (!empty($cArgs)) {
         $cache = Util::hash($name . ':' . \json_encode($cArgs));
     } else {
         $cArgs = [];
         $cache = Util::hash($name . '[]');
     }
     if (!isset($this->_cache['blueprints'][$cache])) {
         // CACHE MISS. We need to build it, then!
         $db = $this->airshipChooseDB();
         if ($db instanceof DBInterface) {
             \array_unshift($cArgs, $db);
         }
         try {
             $class = Gears::getName('Blueprint__' . $name);
         } catch (GearNotFound $ex) {
             if ($name[0] === '\\') {
                 // If you pass a \Absolute\Namespace, we will just use it.
                 $class = $name;
             } else {
                 // We default to \Current\Application\Namespace\Blueprint\NameHere.
                 $x = \explode('\\', $this->getNamespace());
                 \array_pop($x);
                 $class = \implode('\\', $x) . '\\Blueprint\\' . $name;
             }
         }
         $this->_cache['blueprints'][$cache] = new $class(...$cArgs);
         if (!$this->_cache['blueprints'][$cache] instanceof Blueprint) {
             throw new InvalidType(\trk('errors.type.wrong_class', 'Blueprint'));
         }
         \Airship\tightenBolts($this->_cache['blueprints'][$cache]);
     }
     return $this->_cache['blueprints'][$cache];
 }