プロセスは緩めたほうがいい
$task1 = new Task ( array (
"code",
"code1",
"differs",
"code2",
"code3",
function () {
echo "Sample Function";
}
) );
$task2 = new Task ( array (
"code",
"code1",
"differs",
"differs",
"code3",
array (
"Code2,Code4"
)
) );
echo "<pre />";
$process = new Process ( $task1 );
$process->run ();
echo PHP_EOL;
echo PHP_EOL;
$process = new Process ( $task2 );
$process->run ();
クラス
class Task {
private $process = array ();
function __construct($process) {
$this->process = $process;
}
function add($name) {
$this->process [] = $name;
}
function getProcess($i = null) {
return ($i == null) ? $this->process : $this->process [$i];
}
function getTotal() {
return count ( $this->process );
}
}
class Process {
private $task;
function __construct(Task $task) {
$this->task = $task;
}
function run() {
for($i = 0; $i < $this->task->getTotal (); $i ++) {
$run = $this->task->getProcess ( $i );
if (is_callable ( $run )) {
$run ();
} else if (is_string ( $run )) {
echo "Running " . $run, PHP_EOL;
}
}
}
}
出力
Running code1
Running differs
Running code2
Running code3
Sample Function
Running code1
Running differs
Running differs
Running code3