private function DomainsReceive::readSettings in DRD Agent 8.3
Same name and namespace in other branches
- 4.0.x src/Agent/Action/DomainsReceive.php \Drupal\drd_agent\Agent\Action\DomainsReceive::readSettings()
Safely read the settings.php file and return the relevant variables.
Parameters
string $shortname: Name of the subdirectory in Drupal's site directory.
string $file: Full path and filename to the settings.php which whould be read.
Return value
array An array containing the base url and database settings.
1 call to DomainsReceive::readSettings()
- DomainsReceive::readSites in src/
Agent/ Action/ DomainsReceive.php - Determines all available sites/domains in the current Drupal installation.
File
- src/
Agent/ Action/ DomainsReceive.php, line 101
Class
- DomainsReceive
- Provides a 'DomainsReceive' code.
Namespace
Drupal\drd_agent\Agent\ActionCode
private function readSettings($shortname, $file) : array {
// The following 2 variables may be required due to Drupal's
// default.settings.php since version 8.2.x.
// @see also https://www.drupal.org/node/2911759
/* @noinspection PhpUnusedLocalVariableInspection */
$app_root = $this->container
->get('app.root');
/* @noinspection PhpUnusedLocalVariableInspection */
$site_path = 'sites/' . $shortname;
/* @noinspection PhpUnusedLocalVariableInspection */
$class_loader = new DummyClassLoader();
$base_url = '';
$databases = [];
try {
$php = php_strip_whitespace($file);
$php = str_replace([
'<?php',
'<?',
'?>',
'ini_set',
'@@ini_set',
], [
'',
'',
'',
'@ini_set',
'@ini_set',
], $php);
file_put_contents('temporary://drd-test.php', $php);
eval($php);
} catch (Exception $e) {
// Ignore it.
$this
->watchdog('Read Settings - Exception occured:<pre>@exception</pre>', [
'@exception' => print_r($e, TRUE),
], LogLevel::ERROR);
return [
'',
'',
];
}
if (empty($base_url)) {
if ($shortname === 'default') {
$base_url = $GLOBALS['base_url'];
}
else {
$base_url = $shortname;
}
}
return [
$base_url,
$databases,
];
}