|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cli\CliBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
6
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
|
7
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Todo\Application\Task\Command; |
|
13
|
|
|
use Todo\Application\Task\Exception\TaskCannotBeSavedException; |
|
14
|
|
|
use Todo\Domain\Exception\TaskNameIsAlreadyExistedException; |
|
15
|
|
|
use Todo\Domain\Exception\TaskNameIsEmptyException; |
|
16
|
|
|
use Todo\Domain\Exception\TaskNotFoundException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class TaskRedoCommand |
|
20
|
|
|
* |
|
21
|
|
|
* @category None |
|
22
|
|
|
* @package Cli\CliBundle\Command |
|
23
|
|
|
* @author Martin Pham <[email protected]> |
|
24
|
|
|
* @license None http:// |
|
25
|
|
|
* @link None |
|
26
|
|
|
*/ |
|
27
|
|
|
class TaskRedoCommand extends ContainerAwareCommand |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* TaskCommand |
|
31
|
|
|
* |
|
32
|
|
|
* @var Command |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $taskCommand; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* TaskListCommand constructor |
|
38
|
|
|
* |
|
39
|
|
|
* @param Command $taskCommand Task Command |
|
40
|
|
|
* |
|
41
|
|
|
* @throws LogicException |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(Command $taskCommand) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->taskCommand = $taskCommand; |
|
46
|
|
|
|
|
47
|
|
|
try { |
|
48
|
|
|
parent::__construct(); |
|
49
|
|
|
} catch (LogicException $e) { |
|
50
|
|
|
throw $e; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Configure |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
* @throws InvalidArgumentException |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function configure() |
|
61
|
|
|
{ |
|
62
|
|
|
try { |
|
63
|
|
|
$this |
|
64
|
|
|
->setName('task:redo') |
|
65
|
|
|
->setDescription('...') |
|
66
|
|
|
->addArgument('id', InputArgument::REQUIRED, 'Task ID'); |
|
67
|
|
|
} catch (InvalidArgumentException $e) { |
|
68
|
|
|
// no catch exception |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Execute |
|
74
|
|
|
* |
|
75
|
|
|
* @param InputInterface $input |
|
76
|
|
|
* @param OutputInterface $output |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
* @throws TaskNotFoundException |
|
80
|
|
|
* @throws TaskCannotBeSavedException |
|
81
|
|
|
* @throws InvalidArgumentException |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
84
|
|
|
{ |
|
85
|
|
|
try { |
|
86
|
|
|
$taskId = $input->getArgument('id'); |
|
87
|
|
|
} catch (InvalidArgumentException $e) { |
|
88
|
|
|
throw $e; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
try { |
|
92
|
|
|
$this->taskCommand->redoTask($taskId); |
|
93
|
|
|
|
|
94
|
|
|
$output->writeln('Task marked remaning'); |
|
95
|
|
|
} catch (TaskNotFoundException | TaskCannotBeSavedException $e) { |
|
96
|
|
|
throw $e; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|