|
1
|
|
|
<?php namespace Comodojo\Installer; |
|
2
|
|
|
|
|
3
|
|
|
use Composer\Composer; |
|
4
|
|
|
use Composer\IO\IOInterface; |
|
5
|
|
|
use Composer\Plugin\PluginInterface; |
|
6
|
|
|
use Comodojo\Configuration\Installer as PackageInstaller; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* |
|
10
|
|
|
* |
|
11
|
|
|
* @package Comodojo Framework |
|
12
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
13
|
|
|
* @author Marco Castiello <[email protected]> |
|
14
|
|
|
* @license GPL-3.0+ |
|
15
|
|
|
* |
|
16
|
|
|
* LICENSE: |
|
17
|
|
|
* |
|
18
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
19
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
20
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
21
|
|
|
* License, or (at your option) any later version. |
|
22
|
|
|
* |
|
23
|
|
|
* This program is distributed in the hope that it will be useful, |
|
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
26
|
|
|
* GNU Affero General Public License for more details. |
|
27
|
|
|
* |
|
28
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
29
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
30
|
|
|
*/ |
|
31
|
|
|
|
|
32
|
|
|
class Plugin implements PluginInterface { |
|
33
|
|
|
|
|
34
|
|
|
public function activate(Composer $composer, IOInterface $io) { |
|
35
|
|
|
|
|
36
|
|
|
$this->loadInstallerConfig($composer); |
|
37
|
|
|
|
|
38
|
|
|
if ( !$this->loadStaticConfiguration($composer) ) { |
|
39
|
|
|
|
|
40
|
|
|
$this->getIO()->write('<comment>Comodojo configuration not (yet) available.</comment>'); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
$installer = new Installer($io, $composer); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
} else { |
|
45
|
|
|
|
|
46
|
|
|
$package_installer = new PackageInstaller(); |
|
47
|
|
|
|
|
48
|
|
|
$installer = new Installer($io, $composer, $package_installer); |
|
49
|
|
|
|
|
50
|
|
|
$this->getIO()->write('<comment>Comodojo configuration loaded, installer ready.</comment>'); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$composer->getInstallationManager()->addInstaller($installer); |
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function loadInstallerConfig(Composer $composer) { |
|
59
|
|
|
|
|
60
|
|
|
$extra = $composer->getPackage()->getExtra(); |
|
61
|
|
|
|
|
62
|
|
|
$installer_default_config = array( |
|
63
|
|
|
'app-assets' => 'public/apps', |
|
64
|
|
|
'framework-js' => 'public/js', |
|
65
|
|
|
'framework-templates' => 'public/templates', |
|
66
|
|
|
'local-cache' => 'cache', |
|
67
|
|
|
'static-config' => 'config', |
|
68
|
|
|
'local-logs' => 'logs', |
|
69
|
|
|
'local-database' => 'database' |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
if ( isset($extra['comodojo-installer-paths']) && is_array($extra['comodojo-installer-paths']) ) { |
|
73
|
|
|
|
|
74
|
|
|
$installer_config = array_replace($installer_default_config, $extra['comodojo-installer-paths']); |
|
75
|
|
|
|
|
76
|
|
|
} else { |
|
77
|
|
|
|
|
78
|
|
|
$installer_config = $installer_default_config; |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
define('COMODOJO_INSTALLER_APP_ASSETS', $installer_config['app-assets']); |
|
83
|
|
|
|
|
84
|
|
|
define('COMODOJO_INSTALLER_THEME_ASSETS', $installer_config['theme-assets']); |
|
85
|
|
|
|
|
86
|
|
|
define('COMODOJO_INSTALLER_LOCAL_CACHE', $installer_config['local-cache']); |
|
87
|
|
|
|
|
88
|
|
|
define('COMODOJO_INSTALLER_STATIC_CONFIG', $installer_config['static-config']); |
|
89
|
|
|
|
|
90
|
|
|
define('COMODOJO_INSTALLER_LOCAL_LOGS', $installer_config['local-logs']); |
|
91
|
|
|
|
|
92
|
|
|
define('COMODOJO_INSTALLER_LOCAL_DATABASE', $installer_config['local-database']); |
|
93
|
|
|
|
|
94
|
|
|
define('COMODOJO_INSTALLER_WORKING_DIRECTORY', getcwd()); |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
private function loadStaticConfiguration() { |
|
99
|
|
|
|
|
100
|
|
|
$config_file = COMODOJO_INSTALLER_WORKING_DIRECTORY.COMODOJO_INSTALLER_STATIC_CONFIG.'/config.php'; |
|
101
|
|
|
|
|
102
|
|
|
if ( is_file($config_file) && is_readable($config_file) ) { |
|
103
|
|
|
|
|
104
|
|
|
include_once($config_file); |
|
105
|
|
|
|
|
106
|
|
|
return true; |
|
107
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
return false; |
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.