Kohana v3.3.2
This commit is contained in:
@@ -170,7 +170,7 @@ class Kohana_Minion_CLI {
|
||||
// Create temporary file
|
||||
file_put_contents($vbscript, 'wscript.echo(InputBox("'.addslashes($text).'"))');
|
||||
|
||||
$password = shell_exec('cscript //nologo '.escapeshellarg($command));
|
||||
$password = shell_exec('cscript //nologo '.escapeshellarg($text));
|
||||
|
||||
// Remove temporary file.
|
||||
unlink($vbscript);
|
||||
|
@@ -33,7 +33,7 @@ class Kohana_Minion_Exception extends Kohana_Exception {
|
||||
{
|
||||
echo Kohana_Exception::text($e);
|
||||
}
|
||||
|
||||
|
||||
$exit_code = $e->getCode();
|
||||
|
||||
// Never exit "0" after an exception.
|
||||
@@ -59,6 +59,6 @@ class Kohana_Minion_Exception extends Kohana_Exception {
|
||||
|
||||
public function format_for_cli()
|
||||
{
|
||||
return Kohana_Exception::text($e);
|
||||
return Kohana_Exception::text($this);
|
||||
}
|
||||
}
|
||||
|
@@ -206,7 +206,7 @@ abstract class Kohana_Minion_Task {
|
||||
public function build_validation(Validation $validation)
|
||||
{
|
||||
// Add a rule to each key making sure it's in the task
|
||||
foreach ($validation->as_array() as $key => $value)
|
||||
foreach ($validation->data() as $key => $value)
|
||||
{
|
||||
$validation->rule($key, array($this, 'valid_option'), array(':validation', ':field'));
|
||||
}
|
||||
|
33
modules/minion/composer.json
Normal file
33
modules/minion/composer.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "kohana/minion",
|
||||
"type": "kohana-module",
|
||||
"description": "The official kohana module for running tasks via the CLI",
|
||||
"homepage": "http://kohanaframework.org",
|
||||
"license": "BSD-3-Clause",
|
||||
"keywords": ["kohana", "framework", "task"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kohana Team",
|
||||
"email": "team@kohanaframework.org",
|
||||
"homepage": "http://kohanaframework.org/team",
|
||||
"role": "developer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "http://dev.kohanaframework.org",
|
||||
"forum": "http://forum.kohanaframework.org",
|
||||
"irc": "irc://irc.freenode.net/kohana",
|
||||
"source": "http://github.com/kohana/core"
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "~1.0",
|
||||
"kohana/core": ">=3.3",
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-3.3/develop": "3.3.x-dev",
|
||||
"dev-3.4/develop": "3.4.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,32 +1,3 @@
|
||||
# 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.
|
||||
[!!] Since Kohana `3.3.x`, minion requires no additional setup to use.
|
@@ -6,8 +6,8 @@ Writing a task in minion is very easy. Simply create a new class called `Task_<T
|
||||
|
||||
class Task_Demo extends Minion_Task
|
||||
{
|
||||
protected $_defaults = array(
|
||||
'foo' = 'bar',
|
||||
protected $_options = array(
|
||||
'foo' => 'bar',
|
||||
'bar' => NULL,
|
||||
);
|
||||
|
||||
@@ -28,7 +28,7 @@ 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.
|
||||
- It needs to have a `protected $_options` 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
|
||||
|
||||
@@ -68,4 +68,4 @@ Tasks can have built-in help. Minion will read class docblocks that you specify:
|
||||
*/
|
||||
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.
|
||||
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.
|
||||
|
70
modules/minion/tests/minion/TaskTest.php
Normal file
70
modules/minion/tests/minion/TaskTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test case for Minion_Util
|
||||
*
|
||||
* @package Kohana/Minion
|
||||
* @group kohana
|
||||
* @group kohana.minion
|
||||
* @category Test
|
||||
* @author Kohana Team
|
||||
* @copyright (c) 2009-2012 Kohana Team
|
||||
* @license http://kohanaframework.org/license
|
||||
*/
|
||||
|
||||
class Minion_TaskTest extends Kohana_Unittest_TestCase
|
||||
{
|
||||
/**
|
||||
* Provides test data for test_convert_task_to_class_name()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provider_convert_task_to_class_name()
|
||||
{
|
||||
return array(
|
||||
array('Task_Db_Migrate', 'db:migrate'),
|
||||
array('Task_Db_Status', 'db:status'),
|
||||
array('', ''),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a task can be converted to a class name
|
||||
*
|
||||
* @test
|
||||
* @covers Minion_Task::convert_task_to_class_name
|
||||
* @dataProvider provider_convert_task_to_class_name
|
||||
* @param string Expected class name
|
||||
* @param string Input task name
|
||||
*/
|
||||
public function test_convert_task_to_class_name($expected, $task_name)
|
||||
{
|
||||
$this->assertSame($expected, Minion_Task::convert_task_to_class_name($task_name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for test_convert_class_to_task()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provider_convert_class_to_task()
|
||||
{
|
||||
return array(
|
||||
array('db:migrate', 'Task_Db_Migrate'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the task name can be found from a class name / object
|
||||
*
|
||||
* @test
|
||||
* @covers Minion_Task::convert_class_to_task
|
||||
* @dataProvider provider_convert_class_to_task
|
||||
* @param string Expected task name
|
||||
* @param mixed Input class
|
||||
*/
|
||||
public function test_convert_class_to_task($expected, $class)
|
||||
{
|
||||
$this->assertSame($expected, Minion_Task::convert_class_to_task($class));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user