Permalink
Browse files

removing Util class

  • Loading branch information...
1 parent b45a945 commit 855a7c6fae1406955a3e68fc84aa0fba3d7daf66 @Zeelot Zeelot committed Feb 28, 2012
Showing with 123 additions and 143 deletions.
  1. +123 −6 classes/Kohana/Minion/Task.php
  2. +0 −128 classes/Kohana/Minion/Util.php
  3. +0 −9 classes/Minion/Util.php
@@ -11,6 +11,44 @@
abstract class Kohana_Minion_Task {
/**
+ * The separator used to separate different levels of tasks
+ * @var string
+ */
+ public static $task_separator = ':';
+
+ /**
+ * Converts a task (e.g. db:migrate to a class name)
+ *
+ * @param string Task name
+ * @return string Class name
+ */
+ public static function convert_task_to_class_name($task)
+ {
+ $task = trim($task);
+
+ if (empty($task))
+ return '';
+
+ return 'Task_'.implode('_', array_map('ucfirst', explode(Minion_Task::$task_separator, $task)));
+ }
+
+ /**
+ * Gets the task name of a task class / task object
+ *
+ * @param string|Minion_Task The task class / object
+ * @return string The task name
+ */
+ public static function convert_class_to_task($class)
+ {
+ if (is_object($class))
+ {
+ $class = get_class($class);
+ }
+
+ return strtolower(str_replace('_', Minion_Task::$task_separator, substr($class, 5)));
+ }
+
+ /**
* The list of options this task accepts and their default values.
*
* protected $_options = array(
@@ -52,7 +90,7 @@ public static function factory($options)
$task = 'help';
}
- $class = Minion_Util::convert_task_to_class_name($task);
+ $class = Minion_Task::convert_task_to_class_name($task);
if ( ! in_array('Minion_Task', class_parents($class)))
{
@@ -97,7 +135,7 @@ public function __toString()
if ($task_name === NULL)
{
- $task_name = Minion_Util::convert_class_to_task($this);
+ $task_name = Minion_Task::convert_class_to_task($this);
}
return $task_name;
@@ -189,7 +227,7 @@ public function execute()
if ( $this->_method != '_help' AND ! $validation->check())
{
echo View::factory('minion/error/validation')
- ->set('task', Minion_Util::convert_class_to_task($this))
+ ->set('task', Minion_Task::convert_class_to_task($this))
->set('errors', $validation->errors($this->get_errors_file()));
}
else
@@ -209,16 +247,16 @@ public function execute()
*/
protected function _help(array $params)
{
- $tasks = Minion_Util::compile_task_list(Kohana::list_files('classes/task'));
+ $tasks = $this->_compile_task_list(Kohana::list_files('classes/task'));
$inspector = new ReflectionClass($this);
- list($description, $tags) = Minion_Util::parse_doccomment($inspector->getDocComment());
+ list($description, $tags) = $this->_parse_doccomment($inspector->getDocComment());
$view = View::factory('minion/help/task')
->set('description', $description)
->set('tags', (array) $tags)
- ->set('task', Minion_Util::convert_class_to_task($this));
+ ->set('task', Minion_Task::convert_class_to_task($this));
echo $view;
}
@@ -231,4 +269,83 @@ public function valid_option(Validation $validation, $option)
$validation->error($key, 'minion_option');
}
}
+
+ /**
+ * Parses a doccomment, extracting both the comment and any tags associated
+ *
+ * Based on the code in Kodoc::parse()
+ *
+ * @param string The comment to parse
+ * @return array First element is the comment, second is an array of tags
+ */
+ protected function _parse_doccomment($comment)
+ {
+ // Normalize all new lines to \n
+ $comment = str_replace(array("\r\n", "\n"), "\n", $comment);
+
+ // Remove the phpdoc open/close tags and split
+ $comment = array_slice(explode("\n", $comment), 1, -1);
+
+ // Tag content
+ $tags = array();
+
+ foreach ($comment as $i => $line)
+ {
+ // Remove all leading whitespace
+ $line = preg_replace('/^\s*\* ?/m', '', $line);
+
+ // Search this line for a tag
+ if (preg_match('/^@(\S+)(?:\s*(.+))?$/', $line, $matches))
+ {
+ // This is a tag line
+ unset($comment[$i]);
+
+ $name = $matches[1];
+ $text = isset($matches[2]) ? $matches[2] : '';
+
+ $tags[$name] = $text;
+ }
+ else
+ {
+ $comment[$i] = (string) $line;
+ }
+ }
+
+ $comment = trim(implode("\n", $comment));
+
+ return array($comment, $tags);
+ }
+
+ /**
+ * Compiles a list of available tasks from a directory structure
+ *
+ * @param array Directory structure of tasks
+ * @param string prefix
+ * @return array Compiled tasks
+ */
+ protected function _compile_task_list(array $files, $prefix = '')
+ {
+ $output = array();
+
+ foreach ($files as $file => $path)
+ {
+ $file = substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1);
+
+ if (is_array($path) AND count($path))
+ {
+ $task = $this->_compile_task_list($path, $prefix.$file.Minion_Task::$task_separator);
+
+ if ($task)
+ {
+ $output = array_merge($output, $task);
+ }
+ }
+ else
+ {
+ $output[] = strtolower($prefix.substr($file, 0, -strlen(EXT)));
+ }
+ }
+
+ return $output;
+ }
}
@@ -1,128 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-/**
- * Minion utility class
- *
- * @package Kohana
- * @category Minion
- * @author Kohana Team
- * @copyright (c) 2009-2011 Kohana Team
- * @license http://kohanaframework.org/license
- */
-class Kohana_Minion_Util
-{
- /**
- * The separator used to separate different levels of tasks
- * @var string
- */
- public static $task_separator = ':';
-
- /**
- * Parses a doccomment, extracting both the comment and any tags associated
- *
- * Based on the code in Kodoc::parse()
- *
- * @param string The comment to parse
- * @return array First element is the comment, second is an array of tags
- */
- public static function parse_doccomment($comment)
- {
- // Normalize all new lines to \n
- $comment = str_replace(array("\r\n", "\n"), "\n", $comment);
-
- // Remove the phpdoc open/close tags and split
- $comment = array_slice(explode("\n", $comment), 1, -1);
-
- // Tag content
- $tags = array();
-
- foreach ($comment as $i => $line)
- {
- // Remove all leading whitespace
- $line = preg_replace('/^\s*\* ?/m', '', $line);
-
- // Search this line for a tag
- if (preg_match('/^@(\S+)(?:\s*(.+))?$/', $line, $matches))
- {
- // This is a tag line
- unset($comment[$i]);
-
- $name = $matches[1];
- $text = isset($matches[2]) ? $matches[2] : '';
-
- $tags[$name] = $text;
- }
- else
- {
- $comment[$i] = (string) $line;
- }
- }
-
- $comment = trim(implode("\n", $comment));
-
- return array($comment, $tags);
- }
-
- /**
- * Compiles a list of available tasks from a directory structure
- *
- * @param array Directory structure of tasks
- * @return array Compiled tasks
- */
- public static function compile_task_list(array $files, $prefix = '')
- {
- $output = array();
-
- foreach ($files as $file => $path)
- {
- $file = substr($file, strrpos($file, DIRECTORY_SEPARATOR) + 1);
-
- if (is_array($path) AND count($path))
- {
- $task = Minion_Util::compile_task_list($path, $prefix.$file.Minion_Util::$task_separator);
-
- if ($task)
- {
- $output = array_merge($output, $task);
- }
- }
- else
- {
- $output[] = strtolower($prefix.substr($file, 0, -strlen(EXT)));
- }
- }
-
- return $output;
- }
-
- /**
- * Converts a task (e.g. db:migrate to a class name)
- *
- * @param string Task name
- * @return string Class name
- */
- public static function convert_task_to_class_name($task)
- {
- $task = trim($task);
-
- if (empty($task))
- return '';
-
- return 'Task_'.implode('_', array_map('ucfirst', explode(Minion_Util::$task_separator, $task)));
- }
-
- /**
- * Gets the task name of a task class / task object
- *
- * @param string|Minion_Task The task class / object
- * @return string The task name
- */
- public static function convert_class_to_task($class)
- {
- if (is_object($class))
- {
- $class = get_class($class);
- }
-
- return strtolower(str_replace('_', Minion_Util::$task_separator, substr($class, 5)));
- }
-}
View
@@ -1,9 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-
-
-/**
- * Utility class for Minion
- */
-class Minion_Util extends Kohana_Minion_Util {
-
-}

0 comments on commit 855a7c6

Please sign in to comment.