class DomainsReceive 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
Provides a 'DomainsReceive' code.
Hierarchy
- class \Drupal\drd_agent\Agent\Action\Base implements ContainerInjectionInterface, BaseInterface
- class \Drupal\drd_agent\Agent\Action\DomainsReceive
Expanded class hierarchy of DomainsReceive
File
- src/
Agent/ Action/ DomainsReceive.php, line 11
Namespace
Drupal\drd_agent\Agent\ActionView source
class DomainsReceive extends Base {
/**
* {@inheritdoc}
*/
public function execute() {
$domains = [];
foreach ($this
->readSites() as $uri => $shortname) {
$file = DRUPAL_ROOT . '/sites/' . $shortname . '/settings.php';
if (!file_exists($file)) {
continue;
}
if (isset($domains[$shortname])) {
$domains[$shortname]['aliase'][] = $uri;
}
else {
$domains[$shortname] = [
'uri' => $uri,
'aliase' => [],
];
}
}
return $domains;
}
/**
* Determines all available sites/domains in the current Drupal installation.
*
* @return array
* An array with key/value pairs where key is the domain name and value the
* shortname of a directory in DRUPAL_ROOT/sites/ for where to find the
* settings.php file for that domain.
*/
private function readSites() : array {
$sites = [];
if (file_exists(DRUPAL_ROOT . '/sites/sites.php')) {
try {
/** @noinspection PhpIncludeInspection */
include DRUPAL_ROOT . '/sites/sites.php';
} catch (Exception $e) {
// Ignore.
}
}
if (empty($sites)) {
foreach (scandir(DRUPAL_ROOT . '/sites') as $shortname) {
if (is_dir(DRUPAL_ROOT . '/sites/' . $shortname) && !in_array($shortname, [
'.',
'..',
'all',
])) {
$file = DRUPAL_ROOT . '/sites/' . $shortname . '/settings.php';
if (file_exists($file)) {
list($base_url, ) = $this
->readSettings($shortname, $file);
if (empty($base_url)) {
$this
->watchdog('Reading Sites - Failed as url is empty: @shortname', [
'@shortname' => $shortname,
], LogLevel::ERROR);
continue;
}
$pos = strpos($base_url, '://');
if ($pos > 0) {
$base_url = substr($base_url, $pos + 3);
}
$sites[$base_url] = $shortname;
}
}
}
}
if (empty($sites)) {
$base_url = $GLOBALS['base_url'];
$sites[$base_url] = 'default';
}
$this
->watchdog('Reading Sites - Found @n entries: <pre>@list</pre>', [
'@n' => count($sites),
'@list' => print_r($sites, TRUE),
]);
return $sites;
}
/**
* Safely read the settings.php file and return the relevant variables.
*
* @param string $shortname
* Name of the subdirectory in Drupal's site directory.
* @param string $file
* Full path and filename to the settings.php which whould be read.
*
* @return array
* An array containing the base url and database settings.
*/
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,
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Base:: |
protected | property | ||
Base:: |
private | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | Crypt object for this DRD request. | |
Base:: |
protected | property | ||
Base:: |
private | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
protected | property | ||
Base:: |
private | function | Authenticate the request or throw an exception. | |
Base:: |
public | function |
Authorize the DRD instance, all validations have passed successfully. Overrides BaseInterface:: |
|
Base:: |
public | function | Callback to authorize a DRD instance with a given secret. | |
Base:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
Base:: |
public | function |
Get the arguments for this request. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get authorised Crypt object or FALSE if none is available. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get an array of database connection information. Overrides BaseInterface:: |
|
Base:: |
public | function |
Get the debug mode. Overrides BaseInterface:: |
|
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function |
Validate a one-time-token. Overrides BaseInterface:: |
|
Base:: |
public | function |
Change current session to user 1. Overrides BaseInterface:: |
|
Base:: |
private | function | Read and decode the input from the POST request. | |
Base:: |
public | function |
Overrides BaseInterface:: |
|
Base:: |
public | function | Main callback to execute an action. | |
Base:: |
constant | |||
Base:: |
constant | |||
Base:: |
constant | |||
Base:: |
public | function |
Set the debug mode. Overrides BaseInterface:: |
|
Base:: |
private | function | Recursivly convert request arguments to an array. | |
Base:: |
public | function |
Logging if in debug mode. Overrides BaseInterface:: |
|
Base:: |
public | function | Base constructor. | |
DomainsReceive:: |
public | function |
Execute an action. Overrides Base:: |
|
DomainsReceive:: |
private | function | Safely read the settings.php file and return the relevant variables. | |
DomainsReceive:: |
private | function | Determines all available sites/domains in the current Drupal installation. |