refactor: clean up code and remove some dependencies

This commit is contained in:
2018-11-25 17:35:33 -06:00
parent 2d2122e05d
commit 98b67855ca
19 changed files with 1075 additions and 565 deletions

View File

@@ -0,0 +1,62 @@
<?php
class TodoStrategy implements IStrategy {
public function __construct(TaskwarriorConfig $config){
$this->config = $config;
$this->cmd[] = $this->config->taskBin();
}
public function add(Task $task){
$this->cmd[] = 'add';
if($task->getDescription() != null){
$this->cmd[] = sprintf('"%s"', $task->getDescription());
}
if($task->getCategories() != null){
$categories = implode(' +', $task->getCategories());
$this->cmd[] = $categories;
}
if($task->getDue() != null){
$this->cmd[] = $task->getDue('Y-m-dTH:i:s');
}
if($task->getRecurrence() != null){
$rrule = $task->getRecurrence()->getParts();
$this->cmd[] = sprintf('recur:%s', $rrule['FREQ']);
if(isset($rrule['UNTIL'])){
$this->cmd[] = sprintf('until:%s', $rrule['UNTIL']);
}
}
if($task->getStatus() != null){
$this->cmd[] = sprintf('status:%s', $task->getStatus());
}
return $this->executeCommand($cmd);
}
private function executeCommand($command){
$cmdString = implode(' ', $command);
$process = new Process($cmdString);
$process->run();
if(!$process->isSuccessful()){
throw new TaskwarriorCommandLineException($process);
}
return $process->getOutput();
}
}