/**
  * Get the configuration YAML for this interface as defined in a library YAML file, including
  * the code used to instantiate and update the interface
  *
  * @return SilverSmithNode
  */
 public function getConfig()
 {
     $interfaces = SilverSmith::get_interface_manifest();
     if (isset($interfaces[$this->getType()])) {
         return $interfaces[$this->getType()];
     }
     return false;
 }
 /**
  * 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);
 }
 /**
  * Initializes a new SilverSmith project
  *
  * @see "silversmith help"	 
  * @param The parameters, e.g. from the command line
  */
 public static function init($params = array())
 {
     $no_assets = isset($params['no-assets']);
     if (!file_exists(self::$project_dir . "/_project.yml")) {
         if (isset($params['example'])) {
             $contents = file_get_contents(self::$script_dir . "/code/lib/_project.yml");
         } else {
             $contents = "PageTypes: {}\n\nComponents: {}\n";
         }
         $fh = fopen(self::$project_dir . "/_project.yml", "w");
         fwrite($fh, $contents);
         fclose($fh);
         say(success("Created _project.yml"));
     } else {
         say("File _project.yml already exists.");
     }
     if (!file_exists(self::$project_dir . "/_fixtures.txt")) {
         $fh = fopen(self::$project_dir . "/_fixtures.txt", "w");
         if (isset($params['example'])) {
             fwrite($fh, file_get_contents(self::$script_dir . "/code/lib/_fixtures.txt"));
         }
         fclose($fh);
         say(success("Created _fixtures.txt"));
     } else {
         say("File _fixtures.txt already exists.");
     }
     if (!$no_assets) {
         SilverSmith::add_sample_assets();
     }
 }
        }
        state("Bootstrapping SilverSmith...");
        SilverSmith::set_yaml_path($yml_path);
        SilverSmithProject::load($yml_path);
        SilverSmith::load_field_manifest();
        SilverSmith::load_class_manifest();
        SilverSmith::load_interface_manifest();
        // Check for an upgrade every hour
        $time = time();
        $stamp = @file_get_contents($script_dir . "/upgrade");
        if (!$stamp) {
            $stamp = $time;
        }
        $diff = $time - (int) $stamp;
        if ($diff > 3600) {
            say("Checking for upgrade...");
            SilverSmith::upgrade();
        }
        say("done");
    }
}
// if (SilverSmith::is_upgrade_available() && $action != "upgrade") {
//     warn("*** An upgrade is available ***");
//     state(" Run 'silversmith upgrade' to install.\n");
//     sleep(2);
// }
// Hand off execution to the SilverSmith static class
say("Executing CLI command\n\n");
line();
$action = str_replace("-", "_", $action);
call_user_func("SilverSmith::{$action}", $PARAMS);
 /**
  * Gets the configuration for this form field as defined in its YAML file, e.g.
  * checkbox.yml
  *
  * @return BedrockNode
  */
 public function getConfig()
 {
     $fields = SilverSmith::get_field_manifest();
     if (isset($fields[$this->getCMSField()])) {
         $config = $fields[$this->getCMSField()];
         return $config;
     }
     return new BedrockYAML(null);
 }
 /**
  * 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;
     }
 }