mult1mate\crontab\TaskManager::getTaskCrontabLine PHP Method

getTaskCrontabLine() public static method

Formats task for export into crontab file
public static getTaskCrontabLine ( mult1mate\crontab\TaskInterface $task, string $path, string $php_bin, string $input_file ) : string
$task mult1mate\crontab\TaskInterface
$path string
$php_bin string
$input_file string
return string
    public static function getTaskCrontabLine($task, $path, $php_bin, $input_file)
    {
        $str = '';
        $comment = $task->getComment();
        if (!empty($comment)) {
            $str .= '#' . $comment . PHP_EOL;
        }
        if (TaskInterface::TASK_STATUS_ACTIVE != $task->getStatus()) {
            $str .= '#';
        }
        list($class, $method, $args) = self::parseCommand($task->getCommand());
        $exec_cmd = $php_bin . ' ' . $input_file . ' ' . $class . ' ' . $method . ' ' . implode(' ', $args);
        $str .= $task->getTime() . ' cd ' . $path . '; ' . $exec_cmd . ' 2>&1 > /dev/null';
        return $str . PHP_EOL;
    }

Usage Example

Ejemplo n.º 1
0
 public function testGetTaskCrontabLine()
 {
     $task = TaskMock::createNew();
     $task->setStatus(TaskInterface::TASK_STATUS_INACTIVE);
     $task->setCommand('Class::method()');
     $task->setComment('comment');
     $task->setTime('* * * * *');
     $export = TaskManager::getTaskCrontabLine($task, 'path', 'php', 'index.php');
     $this->assertEquals("#comment\n#* * * * * cd path; php index.php Class method  2>&1 > /dev/null\n", $export);
 }
All Usage Examples Of mult1mate\crontab\TaskManager::getTaskCrontabLine