コード例 #1
0
ファイル: Template.php プロジェクト: wintersilence/kohana-cli
 /**
  * Automatically executed after the task action.
  *
  * @return void
  */
 protected function before()
 {
     parent::before();
     if ($this->auto_render === TRUE) {
         if (empty($this->template)) {
             // Generate path to template from class name
             $this->template = CLI_Tasker::class2path($this);
         }
         // Load the template
         $this->template = View::factory($this->template);
     }
 }
コード例 #2
0
ファイル: Scaffold.php プロジェクト: wintersilence/kohana-cli
 /**
  * Create ClI task class and save in file.
  * 
  *     CLI_Task_Scaffold::create('db/migrate', 'template');
  * 
  * @param  string $name     task name
  * @param  string $template class template, uses [CLI_Task_Scaffold::$templates]
  * @return void
  * @throws CLI_Exception
  */
 public static function create($name, $template)
 {
     // Generate task filename
     $filename = APPPATH . CLI_Tasker::DIR_ROOT . Text::ucfirst($name, '/') . EXT;
     $filename = str_replace(array('_', '/'), DIRECTORY_SEPARATOR, $filename);
     // Create task directory if it's not exist
     $dirname = dirname($filename);
     if (!is_dir($dirname) and !mkdir($dirname, 0755, TRUE)) {
         throw new CLI_Exception('Method :method: can not create directory `:dirname`', array(':method' => __METHOD__, ':dirname' => $dirname));
     }
     // Create class content
     $content = View::factory(CLI_Task_Scaffold::$templates[$template], array('kohana_cli_class' => CLI_Tasker::name2class($name)));
     // Save task content in file
     if (file_put_contents($filename, $content) === FALSE) {
         throw new CLI_Exception('Method :method: can not create file `:filename`', array(':method' => __METHOD__, ':filename' => $filename));
     }
 }
コード例 #3
0
ファイル: Info.php プロジェクト: wintersilence/kohana-cli
 /**
  * Gets description for instance of [CLI_Task] class.
  * 
  *     $info = CLI_Task_Info::get_info($name);
  * 
  * @param  string|object $name task name or instance of [CLI_Task] class
  * @return array
  */
 public static function get_info($name)
 {
     if (is_object($name)) {
         // Convert object to task name
         $name = CLI_Tasker::class2name($name);
     }
     if (Kohana::$caching) {
         // Create cache key\tag for find task information
         $cache_key = __METHOD__ . '(' . $name . ')';
         // Try load information from cache
         if ($info = Kohana::cache($cache_key)) {
             return $info;
         }
     }
     // Convert task name to class name
     $class = CLI_Tasker::name2class($name);
     // Create task inspector
     $inspector = new ReflectionClass($class);
     // Get class description and convert to display in CLI
     $description = $inspector->getDocComment();
     // Normalize all new lines to `\n`
     $description = str_replace(array("\r\n", "\n"), "\n", $description);
     // Remove the phpdoc open\close tags and split
     $description = array_slice(explode("\n", $description), 1, -1);
     foreach ($description as $i => $line) {
         // Remove all leading whitespace
         $description[$i] = preg_replace('/^\\s*\\* ?/m', '', $line);
     }
     $description = implode(PHP_EOL, $description);
     // Get default options
     $options = (array) $inspector->getProperty('options')->getValue();
     // Combine information in array
     $info = compact('name', 'class', 'description', 'options');
     if (Kohana::$caching) {
         // Cache task information
         Kohana::cache($cache_key, $info, 3600);
     }
     return $info;
 }
コード例 #4
0
ファイル: template.php プロジェクト: wintersilence/kohana-cli
 * @copyright (c) <?php 
echo date('Y');
?>
 Kohana Team
 * @license   http://kohanaframework.org/license
 */
class <?php 
echo $kohana_cli_class;
?>
 extends CLI_Task_Template {

	/**
	 * @var string|object path to template or [View] object
	 */
	protected $template = '<?php 
echo CLI_Tasker::class2path($kohana_cli_class);
?>
';

	/**
	 * @var boolean auto render template
	 **/
	protected $auto_render = TRUE;

	/**
	 * @var array task options as array of option name => default values
	 */
	protected $options = array();

	/**
	 * Automatically executed after the task action.
コード例 #5
0
ファイル: Tasker.php プロジェクト: wintersilence/kohana-cli
 /**
  * Create CLI task.
  * 
  *     CLI_Tasker::factory(CLI::option('task'), CLI::option())->execute();
  * 
  * @param  string $name    task name
  * @param  array  $options values of options 
  * @return instance of [CLI_Task]
  * @throws CLI_Exception
  */
 public static function factory($name = '', array $options = array())
 {
     if (empty($name)) {
         // Use default name if task not set
         $name = CLI_Tasker::$default;
     }
     $class = CLI_Tasker::name2class($name);
     if (!class_exists($class)) {
         throw new CLI_Exception('Method :method: class `:class` not exists', array(':method' => __METHOD__, ':class' => $class));
     } elseif (!is_subclass_of($class, CLI_Tasker::PARENT_CLASS)) {
         throw new CLI_Exception('Method :method: class `:class` not extended `:parent`', array(':method' => __METHOD__, ':class' => $class, ':parent' => CLI_Tasker::PARENT_CLASS));
     }
     $class = new $class($options);
     return $class;
 }