Upgrade to KH 3.3.0
This commit is contained in:
3
includes/kohana/modules/minion/guide/minion/index.md
Normal file
3
includes/kohana/modules/minion/guide/minion/index.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Minion
|
||||
|
||||
Minion is a simple command line task runner.
|
3
includes/kohana/modules/minion/guide/minion/menu.md
Normal file
3
includes/kohana/modules/minion/guide/minion/menu.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## [Minion]()
|
||||
- [Setup](setup)
|
||||
- [Writing a Task](tasks)
|
32
includes/kohana/modules/minion/guide/minion/setup.md
Normal file
32
includes/kohana/modules/minion/guide/minion/setup.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Minion Setup
|
||||
|
||||
To use minion, you'll need to make a small change to your index.php file:
|
||||
|
||||
-/**
|
||||
- * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
|
||||
- * If no source is specified, the URI will be automatically detected.
|
||||
- */
|
||||
-echo Request::factory()
|
||||
- ->execute()
|
||||
- ->send_headers(TRUE)
|
||||
- ->body();
|
||||
+if (PHP_SAPI == 'cli') // Try and load minion
|
||||
+{
|
||||
+ class_exists('Minion_Task') OR die('minion required!');
|
||||
+ set_exception_handler(array('Kohana_Minion_Exception_Handler', 'handler'));
|
||||
+
|
||||
+ Minion_Task::factory(Minion_CLI::options())->execute();
|
||||
+}
|
||||
+else
|
||||
+{
|
||||
+ /**
|
||||
+ * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
|
||||
+ * If no source is specified, the URI will be automatically detected.
|
||||
+ */
|
||||
+ echo Request::factory()
|
||||
+ ->execute()
|
||||
+ ->send_headers(TRUE)
|
||||
+ ->body();
|
||||
+}
|
||||
|
||||
This will short-circuit your index file to intercept any cli calls, and route them to the minion module.
|
71
includes/kohana/modules/minion/guide/minion/tasks.md
Normal file
71
includes/kohana/modules/minion/guide/minion/tasks.md
Normal file
@@ -0,0 +1,71 @@
|
||||
# Writing Tasks
|
||||
|
||||
Writing a task in minion is very easy. Simply create a new class called `Task_<Taskname>` and put it inside `classes/task/<taskname>.php`.
|
||||
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
class Task_Demo extends Minion_Task
|
||||
{
|
||||
protected $_defaults = array(
|
||||
'foo' = 'bar',
|
||||
'bar' => NULL,
|
||||
);
|
||||
|
||||
/**
|
||||
* This is a demo task
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function _execute(array $params)
|
||||
{
|
||||
var_dump($params);
|
||||
echo 'foobar';
|
||||
}
|
||||
}
|
||||
|
||||
You'll notice a few things here:
|
||||
|
||||
- You need a main `_execute()` method. It should take one array parameter.
|
||||
- This parameter contains any command line options passed to the task.
|
||||
- For example, if you call the task above with `./minion --task=demo --foo=foobar` then `$params` will contain: `array('foo' => 'foobar', 'bar' => NULL)`
|
||||
- It needs to have a `protected $_defaults` array. This is a list of parameters you want to accept for this task. Any parameters passed to the task not in this list will be rejected.
|
||||
|
||||
## Namespacing Tasks
|
||||
|
||||
You can "namespace" tasks by placing them all in a subdirectory: `classes/task/database/generate.php`. This task will be named `database:generate` and can be called with this task name.
|
||||
|
||||
# Parameter Validations
|
||||
|
||||
To add validations to your command line options, simply overload the `build_validation()` method in your task:
|
||||
|
||||
public function build_validation(Validation $validation)
|
||||
{
|
||||
return parent::build_validation($validation)
|
||||
->rule('foo', 'not_empty') // Require this param
|
||||
->rule('bar', 'numeric'); // This param should be numeric
|
||||
}
|
||||
|
||||
These validations will run for every task call unless `--help` is passed to the task.
|
||||
|
||||
# Task Help
|
||||
|
||||
Tasks can have built-in help. Minion will read class docblocks that you specify:
|
||||
|
||||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
|
||||
/**
|
||||
* This is a demo task.
|
||||
*
|
||||
* It can accept the following options:
|
||||
* - foo: this parameter does something. It is required.
|
||||
* - bar: this parameter does something else. It should be numeric.
|
||||
*
|
||||
* @package Kohana
|
||||
* @category Helpers
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2009-2011 Kohana Team
|
||||
* @license http://kohanaframework.org/license
|
||||
*/
|
||||
class Minion_Task_Demo extends Minion_Task
|
||||
|
||||
The `@` tags in the class comments will also be displayed in a human readable format. When writing your task comments, you should specify how to use it, and any parameters it accepts.
|
Reference in New Issue
Block a user