|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the puli/cli package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Puli\Cli\Handler; |
|
13
|
|
|
|
|
14
|
|
|
use Puli\Manager\Api\Module\RootModuleFileManager; |
|
15
|
|
|
use RuntimeException; |
|
16
|
|
|
use Webmozart\Console\Api\Args\Args; |
|
17
|
|
|
use Webmozart\Console\Api\IO\IO; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Handles the "plugin" command. |
|
21
|
|
|
* |
|
22
|
|
|
* @since 1.0 |
|
23
|
|
|
* |
|
24
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class PluginCommandHandler |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var RootModuleFileManager |
|
30
|
|
|
*/ |
|
31
|
|
|
private $manager; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Creates the handler. |
|
35
|
|
|
* |
|
36
|
|
|
* @param RootModuleFileManager $manager The root module file manager |
|
37
|
|
|
*/ |
|
38
|
6 |
|
public function __construct(RootModuleFileManager $manager) |
|
39
|
|
|
{ |
|
40
|
6 |
|
$this->manager = $manager; |
|
41
|
6 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Handles the "puli plugin --list" command. |
|
45
|
|
|
* |
|
46
|
|
|
* @param Args $args The console arguments |
|
47
|
|
|
* @param IO $io The I/O |
|
48
|
|
|
* |
|
49
|
|
|
* @return int The status code |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function handleList(Args $args, IO $io) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
2 |
|
$pluginClasses = $this->manager->getPluginClasses(); |
|
54
|
|
|
|
|
55
|
2 |
|
if (!$pluginClasses) { |
|
|
|
|
|
|
56
|
1 |
|
$io->writeLine('No plugin classes. Use "puli plugin --install <class>" to install a plugin class.'); |
|
57
|
|
|
|
|
58
|
1 |
|
return 0; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
foreach ($pluginClasses as $pluginClass) { |
|
62
|
1 |
|
$io->writeLine(sprintf('<c1>%s</c1>', $pluginClass)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
return 0; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Handles the "puli plugin --install" command. |
|
70
|
|
|
* |
|
71
|
|
|
* @param Args $args The console arguments |
|
72
|
|
|
* |
|
73
|
|
|
* @return int The status code |
|
74
|
|
|
*/ |
|
75
|
2 |
View Code Duplication |
public function handleInstall(Args $args) |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
2 |
|
$pluginClass = $args->getArgument('class'); |
|
78
|
|
|
|
|
79
|
2 |
|
if ($this->manager->hasPluginClass($pluginClass)) { |
|
80
|
1 |
|
throw new RuntimeException(sprintf( |
|
81
|
1 |
|
'The plugin class "%s" is already installed.', |
|
82
|
|
|
$pluginClass |
|
83
|
|
|
)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
1 |
|
$this->manager->addPluginClass($pluginClass); |
|
87
|
|
|
|
|
88
|
1 |
|
return 0; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Handles the "puli plugin --remove" command. |
|
93
|
|
|
* |
|
94
|
|
|
* @param Args $args The console arguments |
|
95
|
|
|
* |
|
96
|
|
|
* @return int The status code |
|
97
|
|
|
*/ |
|
98
|
2 |
View Code Duplication |
public function handleDelete(Args $args) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
2 |
|
$pluginClass = $args->getArgument('class'); |
|
101
|
|
|
|
|
102
|
2 |
|
if (!$this->manager->hasPluginClass($pluginClass)) { |
|
103
|
1 |
|
throw new RuntimeException(sprintf( |
|
104
|
1 |
|
'The plugin class "%s" is not installed.', |
|
105
|
|
|
$pluginClass |
|
106
|
|
|
)); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
$this->manager->removePluginClass($pluginClass); |
|
110
|
|
|
|
|
111
|
1 |
|
return 0; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.