Skip to content

Commit 395a002

Browse files
committed
0.0.1
1 parent a4e0841 commit 395a002

5 files changed

Lines changed: 189 additions & 0 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#IDE
2+
/.idea/
3+
4+
#Composer
5+
/vendor/
6+
/composer.lock

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# CodeMommy TaskPHP
2+
3+
[![License](https://poser.pugx.org/CodeMommy/TaskPHP/license?format=flat-square)](LICENSE)
4+
[![Download](https://poser.pugx.org/CodeMommy/TaskPHP/downloads?format=flat-square)](https://packagist.org/packages/CodeMommy/TaskPHP)
5+
[![Stable](https://poser.pugx.org/CodeMommy/TaskPHP/version?format=flat-square)](https://packagist.org/packages/CodeMommy/TaskPHP)
6+
[![Unstable](https://poser.pugx.org/CodeMommy/TaskPHP/v/unstable?format=flat-square)](https://packagist.org/packages/CodeMommy/TaskPHP)
7+
[![composer.lock Available](https://poser.pugx.org/CodeMommy/TaskPHP/composerlock?format=flat-square)](https://packagist.org/packages/CodeMommy/TaskPHP)
8+
9+
> Run task
10+
11+
Visit [CodeMommy Website](http://www.codemommy.com) or [Packagist](https://packagist.org/packages/CodeMommy/TaskPHP) to get more information.
12+
13+
## Authors
14+
15+
| Name | Identity | Social |
16+
| :--- | :------- | :----- |
17+
| Candison November | Creator | [Website](http://www.kandisheng.com) - [GitHub](https://github.com/KanDisheng) |
18+
19+
## More
20+
21+
- [Feedback](https://github.com/CodeMommy/TaskPHP/issues)
22+
- [About CodeMommy](https://github.com/CodeMommy/CodeMommy)

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "codemommy/taskphp",
3+
"version": "0.0.1",
4+
"description": "Run task",
5+
"keywords": [
6+
"CodeMommy",
7+
"TaskPHP",
8+
"PHP"
9+
],
10+
"license": "Apache 2.0",
11+
"homepage": "http://www.codemommy.com",
12+
"support": {
13+
"issues": "https://github.com/CodeMommy/TaskPHP/issues",
14+
"source": "https://github.com/CodeMommy/TaskPHP"
15+
},
16+
"authors": [
17+
{
18+
"name": "Candison November",
19+
"email": "kandisheng@163.com",
20+
"homepage": "http://www.kandisheng.com"
21+
}
22+
],
23+
"autoload": {
24+
"psr-4": {
25+
"CodeMommy\\TaskPHP\\": "source/"
26+
}
27+
},
28+
"require": {
29+
"php": ">=5.3.0"
30+
}
31+
}

source/Task.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
/**
4+
* CodeMommy TaskPHP
5+
* @author Candison November <www.kandisheng.com>
6+
*/
7+
8+
namespace CodeMommy\TaskPHP;
9+
10+
class Task
11+
{
12+
private static $task = array();
13+
private static $config = array();
14+
15+
/**
16+
* Get Command
17+
* @return null
18+
*/
19+
private static function getCommand()
20+
{
21+
if (isset($_SERVER['argv'][1])) {
22+
return $_SERVER['argv'][1];
23+
}
24+
return null;
25+
}
26+
27+
/**
28+
* Default Task
29+
*/
30+
private static function taskHelp()
31+
{
32+
if (!empty(self::$config)) {
33+
echo(sprintf('%s %s%s', self::$config['title'], self::$config['version'], PHP_EOL));
34+
self::line();
35+
}
36+
echo(sprintf('Tasks are:%s', PHP_EOL));
37+
self::line();
38+
ksort(self::$task);
39+
foreach (self::$task as $value) {
40+
echo(sprintf('%s - %s%s', $value[0], $value[1], PHP_EOL));
41+
}
42+
}
43+
44+
/**
45+
* Get Parameter
46+
*
47+
* @param $number
48+
* @param string $default
49+
*
50+
* @return string
51+
*/
52+
public static function getParameter($number, $default = '')
53+
{
54+
array_shift($_SERVER['argv']);
55+
array_shift($_SERVER['argv']);
56+
if (isset($_SERVER['argv'][$number])) {
57+
return $_SERVER['argv'][$number];
58+
}
59+
return $default;
60+
}
61+
62+
/**
63+
* Line
64+
*/
65+
public static function line()
66+
{
67+
echo(sprintf('--------------------%s', PHP_EOL));
68+
}
69+
70+
/**
71+
* Config
72+
*
73+
* @param $title
74+
* @param $version
75+
*/
76+
public static function config($title, $version)
77+
{
78+
self::$config['title'] = $title;
79+
self::$config['version'] = $version;
80+
}
81+
82+
/**
83+
* Add
84+
*
85+
* @param $command
86+
* @param $about
87+
* @param $function
88+
*/
89+
public static function add($command, $about, $function)
90+
{
91+
self::$task[strtolower($command)] = array($command, $about, $function);
92+
}
93+
94+
/**
95+
* Run
96+
*/
97+
public static function run()
98+
{
99+
self::add('help', 'Help', '');
100+
$command = strtolower(self::getCommand());
101+
if ($command == 'help') {
102+
self::taskHelp();
103+
return;
104+
}
105+
if (isset(self::$task[$command])) {
106+
$command = self::$task[$command][2];
107+
$command();
108+
return;
109+
}
110+
self::taskHelp();
111+
}
112+
}

test/index.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/**
4+
* @author Candison November <www.kandisheng.com>
5+
*/
6+
7+
require_once(__DIR__ . '/../vendor/autoload.php');
8+
9+
use CodeMommy\TaskPHP\Task;
10+
11+
function demo()
12+
{
13+
echo 'demo';
14+
}
15+
16+
Task::config('Task Demo', '1.0.0');
17+
Task::add('demo', 'Demo', 'demo');
18+
Task::run();

0 commit comments

Comments
 (0)