1
|
|
|
<?php |
2
|
|
|
namespace Samurai\Module\Task\Factory; |
3
|
|
|
|
4
|
|
|
use Pimple\Container; |
5
|
|
|
use Samurai\Module\ModuleCommand; |
6
|
|
|
use Samurai\Module\Task\Enabling; |
7
|
|
|
use Samurai\Module\Task\Installing; |
8
|
|
|
use Samurai\Module\Task\Listing; |
9
|
|
|
use Samurai\Module\Task\Removing; |
10
|
|
|
use Samurai\Module\Task\Running; |
11
|
|
|
use Samurai\Module\Task\Saving; |
12
|
|
|
use Samurai\Module\Task\Updating; |
13
|
|
|
use Samurai\Task\ITask; |
14
|
|
|
use SimilarText\Finder; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class TaskFactory |
19
|
|
|
* @package Samurai\Alias\Task\Factory |
20
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ModuleManagementTaskFactory |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param InputInterface $input |
26
|
|
|
* @param Container $services |
27
|
|
|
* @return ITask |
28
|
|
|
*/ |
29
|
10 |
|
public static function create(InputInterface $input, Container $services) |
30
|
|
|
{ |
31
|
|
|
|
32
|
10 |
|
if(!$input->getArgument('action')){ |
33
|
|
|
throw new \InvalidArgumentException(sprintf('An action param is required: %s', json_encode(ModuleCommand::$actions))); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
10 |
|
if($input->getArgument('action') === 'list'){ |
37
|
1 |
|
return new Listing($services); |
38
|
|
|
} |
39
|
9 |
|
if($input->getArgument('action') === 'install'){ |
40
|
2 |
|
return new Installing($services); |
41
|
|
|
} |
42
|
7 |
|
if($input->getArgument('action') === 'update'){ |
43
|
2 |
|
return new Updating($services); |
44
|
|
|
} |
45
|
5 |
View Code Duplication |
if($input->getArgument('action') === 'rm' || $input->getArgument('action') === 'remove'){ |
46
|
2 |
|
if(!$input->getArgument('name')){ |
47
|
|
|
throw new \InvalidArgumentException('name param is mandatory for this action'); |
48
|
|
|
} |
49
|
2 |
|
return new Removing($services); |
50
|
|
|
} |
51
|
3 |
View Code Duplication |
if($input->getArgument('action') === 'enable'){ |
52
|
|
|
if(!$input->getArgument('name')){ |
53
|
|
|
throw new \InvalidArgumentException('name param is mandatory for this action'); |
54
|
|
|
} |
55
|
|
|
return new Enabling($services); |
56
|
|
|
} |
57
|
3 |
View Code Duplication |
if($input->getArgument('action') === 'disable'){ |
58
|
|
|
if(!$input->getArgument('name')){ |
59
|
|
|
throw new \InvalidArgumentException('name param is mandatory for this action'); |
60
|
|
|
} |
61
|
|
|
return new Enabling($services); |
62
|
|
|
} |
63
|
3 |
|
if($input->getArgument('action') === 'run'){ |
64
|
2 |
|
return new Running($services); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
$textFinder = new Finder($input->getArgument('action'), ModuleCommand::$actions); |
68
|
1 |
|
throw new \InvalidArgumentException(sprintf( |
69
|
1 |
|
'Action "%s" not supported. Did you mean "%s"?', |
70
|
1 |
|
$input->getArgument('action'), |
71
|
1 |
|
$textFinder->first() |
72
|
1 |
|
)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.