|
1
|
|
|
<?php |
|
2
|
|
|
namespace Samurai\Alias\Task\Factory; |
|
3
|
|
|
|
|
4
|
|
|
use Pimple\Container; |
|
5
|
|
|
use Samurai\Alias\AliasCommand; |
|
6
|
|
|
use Samurai\Alias\Task\Listing; |
|
7
|
|
|
use Samurai\Alias\Task\Removing; |
|
8
|
|
|
use Samurai\Alias\Task\Saving; |
|
9
|
|
|
use Samurai\Task\ITask; |
|
10
|
|
|
use SimilarText\Finder; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class TaskFactory |
|
15
|
|
|
* @package Samurai\Alias\Task\Factory |
|
16
|
|
|
* @author Raphaël Lefebvre <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class AliasManagementTaskFactory |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @param InputInterface $input |
|
22
|
|
|
* @param Container $services |
|
23
|
|
|
* @return ITask |
|
24
|
|
|
*/ |
|
25
|
9 |
|
public function create(InputInterface $input, Container $services) |
|
26
|
|
|
{ |
|
27
|
9 |
|
if(!$input->getArgument('action')){ |
|
28
|
|
|
throw new \InvalidArgumentException(sprintf('An action param is required: %s', json_encode(AliasCommand::$actions))); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
9 |
|
if($input->getArgument('action') === 'list'){ |
|
32
|
4 |
|
return new Listing($services); |
|
33
|
|
|
} |
|
34
|
5 |
View Code Duplication |
if($input->getArgument('action') === 'save'){ |
|
35
|
2 |
|
if(!$input->getArgument('name')){ |
|
36
|
|
|
throw new \InvalidArgumentException('name param is mandatory for this action'); |
|
37
|
|
|
} |
|
38
|
2 |
|
if(!$input->getArgument('bootstrap')){ |
|
39
|
|
|
throw new \InvalidArgumentException('bootstrap param is mandatory for this action'); |
|
40
|
|
|
} |
|
41
|
2 |
|
return new Saving($services); |
|
42
|
|
|
} |
|
43
|
3 |
View Code Duplication |
if($input->getArgument('action') === 'rm' || $input->getArgument('action') === 'remove'){ |
|
44
|
3 |
|
if(!$input->getArgument('name')){ |
|
45
|
|
|
throw new \InvalidArgumentException('name param is mandatory for this action'); |
|
46
|
|
|
} |
|
47
|
3 |
|
return new Removing($services); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$textFinder = new Finder($input->getArgument('action'), AliasCommand::$actions); |
|
51
|
|
|
throw new \InvalidArgumentException(sprintf( |
|
52
|
|
|
'Action "%s" not supported. Did you mean "%s"?', |
|
53
|
|
|
$input->getArgument('action'), |
|
54
|
|
|
$textFinder->first() |
|
55
|
|
|
)); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
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.