/** * Writes the generated code to a .php file * * @return void */ public function write() { if (!file_exists("code/{$this->key}.php")) { $fh = fopen("code/{$this->key}.php", "w"); $path = SilverSmith::get_script_dir() . "/code/lib/structures/PageType.bedrock"; if (file_exists($path)) { $template = new BedrockTemplate($path); $template->bind($this); fwrite($fh, $template->render()); fclose($fh); } } }
/** * Creates a PHP file on the disk for the class that will define this node * */ public function createFile() { $path = $this->getFilePath(); $stock = $this->getDecorator() ? "Decorator" : $this->getContentType(); $content = file_get_contents(SilverSmith::get_script_dir() . "/code/lib/structures/{$stock}.bedrock"); $template = new BedrockTemplate($content); $template->bind($this); $new_content = str_replace("[?php", "<?php", $template->render()); $fh = fopen($path, "w"); fwrite($fh, $new_content); fclose($fh); }
$script_dir = dirname(dirname(__FILE__)); require_once "{$script_dir}/code/lib/bedrock/Bedrock.php"; require_once "{$script_dir}/code/SilverSmithNode.php"; require_once "{$script_dir}/code/BedrockDataRecord.php"; foreach (glob("{$script_dir}/code/*.php") as $class) { require_once $class; } require_once "{$script_dir}/code/lib/thirdparty/TextDiff.php"; // Bootstrap the SilverSmith class SilverSmith::set_cli(true); SilverSmith::set_script_dir($script_dir); SilverSmith::set_git_path(trim(shell_exec("which git"))); SilverSmithDefaults::load(SilverSmith::get_script_dir() . "/code/lib/_defaults.yml"); SilverSmithSpec::load(SilverSmith::get_script_dir() . "/code/lib/_spec.yml"); // Validation for the CLI commands $commands = new BedrockYAML(SilverSmith::get_script_dir() . "/code/lib/_cli.yml"); $allowed_actions = $commands->getAllowedActions(); $PARAMS = SilverSmithUtil::parse_parameters(); if (!isset($PARAMS[1])) { fail("Usage: silversmith <command> [-args]. Type 'silversmith help' for more information."); } $action = $PARAMS[1]; if (!$allowed_actions->get($action)) { say(error("'{$action}' is not an allowed command.")); say("Available commands:\n " . implode("\n", array_keys($allowed_actions->toArray()))); die; } $allowed_options = $allowed_actions->get($action)->getOptions(); foreach ($PARAMS as $k => $v) { if (!is_numeric($k) && !$allowed_options->get($k)) { say(error("Option '{$k}' is not allowed."));
/** * Binds the component to a {@link BedrockTemplate} and creates the PHP code that defines the * component in SilverStripe * * @return string */ public function getGeneratedCode() { $path = SilverSmith::get_script_dir() . "/code/lib/structures/ComponentCode.bedrock"; if (file_exists($path)) { $template = new BedrockTemplate(file_get_contents($path)); $template->bind($this); $code = $template->render(); return $code; } }