-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathCoreApp.php
More file actions
231 lines (199 loc) · 10.4 KB
/
CoreApp.php
File metadata and controls
231 lines (199 loc) · 10.4 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
namespace exface\Core;
use exface\Core\CommonLogic\AppInstallers\ApacheServerInstaller;
use exface\Core\CommonLogic\AppInstallers\AppDocsInstaller;
use exface\Core\CommonLogic\AppInstallers\NginxServerInstaller;
use exface\Core\Exceptions\Installers\InstallerRuntimeError;
use exface\Core\Facades\LogHubFacade;
use exface\Core\Facades\PermalinkFacade;
use exface\Core\Interfaces\InstallerInterface;
use exface\Core\Factories\ConfigurationFactory;
use exface\Core\Interfaces\AppInterface;
use exface\Core\CommonLogic\Model\App;
use exface\Core\Facades\AbstractHttpFacade\HttpFacadeInstaller;
use exface\Core\Factories\FacadeFactory;
use exface\Core\Facades\DocsFacade;
use exface\Core\Facades\HttpFileServerFacade;
use exface\Core\Facades\WebConsoleFacade;
use exface\Core\CommonLogic\AppInstallers\FileContentInstaller;
use exface\Core\CommonLogic\Filemanager;
use exface\Core\Facades\HttpTaskFacade;
use exface\Core\CommonLogic\AppInstallers\SchedulerInstaller;
use exface\Core\Facades\PWAapiFacade;
use exface\Core\DataTypes\ServerSoftwareDataType;
use exface\Core\CommonLogic\AppInstallers\IISServerInstaller;
class CoreApp extends App
{
const CONFIG_SERVER_INSTALLER = 'INSTALLER.SERVER_INSTALLER.CLASS';
const CONFIG_FILENAME_SYSTEM = 'System';
private $config_loading = false;
private $config_loaded = false;
private $system_config = null;
/**
*
* {@inheritDoc}
* @see \exface\Core\CommonLogic\Model\App::getUid()
*/
public function getUid() : ?string
{
// Hardcode the UID of the core app, because some installers might attempt to use it
// before the model is fully functional on first time installing.
return '0x31000000000000000000000000000000';
}
/**
*
* {@inheritDoc}
* @see \exface\Core\CommonLogic\Model\App::getInstaller()
*/
public function getInstaller(InstallerInterface $injected_installer = null)
{
$installer = parent::getInstaller($injected_installer);
// Add the custom core installer, that will take care of model schema updates, etc.
// Make sure, it runs before any other installers do.
$installer->addInstaller(new CoreInstaller($this->getSelector()), true);
// robot.txt
$robotsTxtInstaller = new FileContentInstaller($this->getSelector());
$robotsTxtInstaller
->setFilePath(Filemanager::pathJoin([$this->getWorkbench()->getInstallationPath(), 'robots.txt']))
->setFileTemplatePath('default.robots.txt')
->setMarkerBegin("\n# BEGIN [#marker#]")
->setMarkerEnd('# END [#marker#]')
->addContent('Disallow robots in general', "
User-agent: *
Disallow: /
");
$installer->addInstaller($robotsTxtInstaller);
// Add facade installers for core facades
// HTTP file server facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(HttpFileServerFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// Docs facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(DocsFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// Web console facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(WebConsoleFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// HttpTask facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(HttpTaskFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// PWA API facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(PWAapiFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// Permalink facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(PermalinkFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// LogHub facade
$tplInstaller = new HttpFacadeInstaller($this->getSelector());
$tplInstaller->setFacade(FacadeFactory::createFromString(LogHubFacade::class, $this->getWorkbench()));
$installer->addInstaller($tplInstaller);
// Server installer.
$serverInstallerClass = $this->getServerInstallerClass();
if ($serverInstallerClass !== null) {
$serverInstaller = new $serverInstallerClass($this->getSelector());
$installer->addInstaller($serverInstaller);
} else {
$msg = 'Could not determine server installer class! Consider defining the server installer class ' .
'explicitly by setting "' . self::CONFIG_SERVER_INSTALLER . '" in "System.config.json".';
throw new InstallerRuntimeError(
$installer,
$msg
);
}
// Scheduler
$schedulerInstaller = new SchedulerInstaller($this->getSelector());
$schedulerName = 'Workbench scheduler (' . $this->getWorkbench()->getInstallationName() . ')';
$schedulerInstaller->addTask($schedulerName, 'exface.Core:RunScheduler', null, true);
$installer->addInstaller($schedulerInstaller);
// Docs installer
$docsInstaller = new AppDocsInstaller($this->getSelector());
$installer->addInstaller($docsInstaller);
return $installer;
}
/**
* @return string|null
*/
protected function getServerInstallerClass() : string|null
{
// From config option.
$cfg = $this->getWorkbench()->getConfig();
if($cfg->hasOption(self::CONFIG_SERVER_INSTALLER)) {
$configOption = $this->getWorkbench()->getConfig()->getOption(self::CONFIG_SERVER_INSTALLER);
if(!empty($configOption)) {
return $configOption;
}
}
// Read from PHP constant.
$softwareFamily = ServerSoftwareDataType::getServerSoftwareFamily();
// Guess via folder structure - this is important for backwards compatibility with existing installations.
// Future installations should have a manually defined ``
if(empty($softwareFamily)) {
$path = $this->getWorkbench()->getInstallationPath();
$softwareFamily = match (true) {
// Microsoft IIS runs on windows and has its files mostly in c:\inetpub\wwwroot
ServerSoftwareDataType::isOsWindows() && preg_match('/[Cc]:\\\\inetpub\\\\wwwroot\\\\/', $path) === 1 => ServerSoftwareDataType::SERVER_SOFTWARE_IIS,
// nginx runs on Linux/Unix only and also has wwwroot in its path
ServerSoftwareDataType::isOsLinux() && preg_match('/\/wwwroot\//', $path) === 1 => ServerSoftwareDataType::SERVER_SOFTWARE_NGINX,
// Apache will have www in its path while being able to run on both
ServerSoftwareDataType::isOsWindows() && preg_match("/\\\\www\\\\/", $path) === 1 => ServerSoftwareDataType::SERVER_SOFTWARE_APACHE,
ServerSoftwareDataType::isOsLinux() && preg_match("/\/www\//", $path) === 1 => ServerSoftwareDataType::SERVER_SOFTWARE_APACHE,
default => null
};
if(empty($softwareFamily)) {
return null;
}
}
return match ($softwareFamily) {
ServerSoftwareDataType::SERVER_SOFTWARE_APACHE => '\\' . ltrim(ApacheServerInstaller::class, "\\"),
ServerSoftwareDataType::SERVER_SOFTWARE_IIS => '\\' . ltrim(IISServerInstaller::class, "\\"),
ServerSoftwareDataType::SERVER_SOFTWARE_NGINX => '\\' . ltrim(NginxServerInstaller::class, "\\"),
default => null
};
}
/**
* The configuration of the core consists of two parts: system config and cora app config.
*
* The system config file only exists in the installation scope and cannot
* be overridden on user level. It contains basic options required to
* start a workbench. It can be loaded at any time - even if the workbench
* did not finish starting yet.
*
* The core app config behaves just like any other application configuration
* and contains all the other options - i.e. those not critical for startup.
*
* {@inheritDoc}
* @see App::getConfig()
*/
public function getConfig()
{
// Make sure the system config is loaded in the first place
if ($this->system_config === null){
$this->system_config = ConfigurationFactory::createFromApp($this);
// First from the app folder (without a scope, thus not writable)
$this->system_config->loadConfigFile($this->getConfigFolder() . DIRECTORY_SEPARATOR . $this->getConfigFileName(static::CONFIG_FILENAME_SYSTEM));
// Then from the installation folder (with the special system scope)
$this->system_config->loadConfigFile($this->getWorkbench()->filemanager()->getPathToConfigFolder() . DIRECTORY_SEPARATOR . $this->getConfigFileName(static::CONFIG_FILENAME_SYSTEM), AppInterface::CONFIG_SCOPE_SYSTEM);
}
// Then load the core config on-top - only once and only if the workbench has already started up
if ($this->config_loaded === false) {
// If the workbench has not been fully started yet, just return the system config
if (! $this->getWorkbench()->isStarted() || $this->config_loading === true){
return $this->system_config;
}
// If the workbench finished starting, load the regular core config files - but
// do it only once! Also keep in mind, that loading the config the files might
// call getConfig() again, so also prevent loops whild actually loading
$this->config_loading = true;
$this->setConfig($this->loadConfigFiles($this->system_config));
$this->config_loading = false;
$this->config_loaded = true;
}
return parent::getConfig();
}
}
?>