Airship\Hangar\Commands\Assemble::addautoRun PHP Method

addautoRun() protected method

Add an autoRun entry.
protected addautoRun ( array $run, string $workspace, string $file ) : boolean
$run array
$workspace string
$file string
return boolean
    protected function addautoRun(array $run, string $workspace, string $file) : bool
    {
        static $db_tpl = null;
        if ($db_tpl === null) {
            $db_tpl = \file_get_contents(\dirname(HANGAR_ROOT) . DIRECTORY_SEPARATOR . 'res' . DIRECTORY_SEPARATOR . 'index.php.tmp');
        }
        $hash = Util::hash($file);
        switch ($run['type']) {
            case 'php':
                \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun' . DIRECTORY_SEPARATOR . $hash . '.php', Base64::decode($run['data']));
                \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun.php', 'require_once __DIR__ . DIRECTORY_SEPARATOR . "autoRun" . DIRECTORY_SEPARATOR . "' . $hash . '.php";' . "\n", FILE_APPEND);
                return true;
            case 'mysql':
            case 'pgsql':
                $exec = \str_replace(['@_QUERY_@', '@_DRIVER_@'], [\str_replace('"', '\\"', Base64::decode($run['data'])), $run['type']], $db_tpl);
                // Save the template file:
                \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun' . DIRECTORY_SEPARATOR . $hash . '.php', $exec);
                // Add the autoRun script to the autoRun list:
                \file_put_contents($workspace . DIRECTORY_SEPARATOR . 'autoRun.php', 'require_once __DIR__ . DIRECTORY_SEPARATOR . "autoRun" . DIRECTORY_SEPARATOR . $hash . ".php";' . "\n", FILE_APPEND);
                return true;
            default:
                throw new \Error('Unknown type: ' . $run['type']);
        }
    }