1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YOURLS Composer Installer |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace YOURLS\ComposerInstaller\Commands; |
7
|
|
|
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Defines the 'add-plugin' custom command |
14
|
|
|
* |
15
|
|
|
* @package YOURLS\ComposerInstaller |
16
|
|
|
* @author Ozh <[email protected]> |
17
|
|
|
* @link https://github.com/yourls/composer-installer/ |
18
|
|
|
* @license MIT |
19
|
|
|
*/ |
20
|
|
|
class CommandAddPlugin extends CommandBase |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Configure the composer custom command |
25
|
|
|
*/ |
26
|
1 |
|
protected function configure() |
27
|
|
|
{ |
28
|
1 |
|
$name = 'add-plugin'; |
29
|
1 |
|
$desc = '<warning>Downloads</warning> a <info>YOURLS plugin</info> and add it to your <comment>`user/composer.json`</comment>'; |
30
|
1 |
|
$def = [ new InputArgument('plugins', InputArgument::IS_ARRAY, 'YOURLS plugin(s) to download') ]; |
31
|
|
|
$help = <<<EOT |
32
|
1 |
|
Example: <comment>`composer add-plugin ozh/example-plugin`</comment> |
33
|
|
|
This command downloads plugins in the appropriate subfolder of <comment>user/plugins/</comment>, adds them to |
34
|
|
|
your <comment>user/composer.json</comment> file, and updates dependencies. |
35
|
|
|
Read more at https://github.com/yourls/composer-installer/ |
36
|
|
|
|
37
|
|
|
EOT; |
38
|
|
|
|
39
|
1 |
|
$this->setName($name) |
40
|
1 |
|
->setDescription($desc) |
41
|
1 |
|
->setDefinition($def) |
42
|
1 |
|
->setHelp($help); |
43
|
1 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Execute the composer custom command |
47
|
|
|
* |
48
|
|
|
* @param InputInterface $input Input interface |
49
|
|
|
* @param OutputInterface $output Output interface |
50
|
|
|
*/ |
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* First : composer require -d user joecool/super-plugin --no-update |
55
|
|
|
* This will only create/update the user/composer.json file |
56
|
|
|
*/ |
57
|
|
|
$require = $this->runComposerCommand( |
58
|
|
|
[ |
59
|
|
|
'command' => 'require', |
60
|
|
|
'packages' => $input->getArgument('plugins'), |
61
|
|
|
'--no-update' => true, |
62
|
|
|
'--working-dir' => 'user/', |
63
|
|
|
], |
64
|
|
|
$output |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Now : composer update |
69
|
|
|
* This will actually download newly required packages, ie the plugin |
70
|
|
|
*/ |
71
|
|
|
$update = $this->runComposerCommand( |
72
|
|
|
[ |
73
|
|
|
'command' => 'update', |
74
|
|
|
'--no-scripts' => true, |
75
|
|
|
], |
76
|
|
|
$output |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
// Both command should have returned 0 |
80
|
|
|
if (($require & $update) === 0) { |
81
|
|
|
$output->writeln('Installed !'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|