Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Convert class to task path.
  * 
  *     echo CLI_Tasker::class2path('CLI_Task_DB_Migrate');
  *     // Result: 'cli/db/migrate'
  * 
  * @param  object|string $class class name or or [CLI_Task] object
  * @return string
  */
 public static function class2path($class)
 {
     $path = CLI_Tasker::class2name($class);
     return 'cli' . DIRECTORY_SEPARATOR . $path;
 }