PluginInstaller.php
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Roundcube\Composer;
/**
* @category Plugins
* @package PluginInstaller
* @author Philip Weir <roundcube@tehinterweb.co.uk>
* @license GPL-3.0+
* @version GIT: <git_id>
* @link http://github.com/roundcube/plugin-installer
*/
class PluginInstaller extends ExtensionInstaller
{
protected $composer_type = 'roundcube-plugin';
public function getVendorDir()
{
return getcwd() . DIRECTORY_SEPARATOR . 'plugins';
}
protected function confirmInstall($package_name)
{
$config = $this->composer->getConfig()->get('roundcube');
if (!empty($config['enable-plugin'])) {
$answer = $config['enable-plugin'];
}
else {
$answer = $this->io->askConfirmation("Do you want to activate the plugin $package_name? [Y|n] ", true);
}
return $answer;
}
protected function getConfig($package_name, $config, $add )
{
$cur_config = !empty($config['plugins']) ? ((array) $config['plugins']) : [];
$new_config = $cur_config;
if ($add && !in_array($package_name, $new_config)) {
$new_config[] = $package_name;
}
elseif (!$add && ($i = array_search($package_name, $new_config)) !== false) {
unset($new_config[$i]);
}
if ($new_config != $cur_config) {
$config_val = count($new_config) > 0 ? "[\n\t'" . join("',\n\t'", $new_config) . "',\n];" : "[];";
$result = ['plugins', $config_val];
}
else {
$result = false;
}
return $result;
}
}