Airship\Engine\Gears::lazyForge PHP Method

lazyForge() public static method

Add a new type to the Gears registry
public static lazyForge ( string $index, string $type ) : boolean
$index string
$type string
return boolean
    public static function lazyForge(string $index, string $type) : bool
    {
        $state = State::instance();
        if (!isset($state->gears[$index])) {
            $gears = $state->gears;
            $gears[$index] = $type;
            $state->gears = $gears;
            return true;
        }
        return false;
    }

Usage Example

Example #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);