function smtp_requirements in SMTP Authentication Support 8
Same name and namespace in other branches
- 6 smtp.module \smtp_requirements()
- 7.2 smtp.install \smtp_requirements()
- 7 smtp.install \smtp_requirements()
Implements hook_requirements().
File
- ./
smtp.install, line 86 - The installation instructions for the SMTP Authentication Support.
Code
function smtp_requirements(string $phase) {
$requirements = [];
if ($phase == 'runtime') {
// Ensure PHPMailer exists.
if (class_exists(PHPMailer::class)) {
$mail = new PHPMailer();
}
if (empty($mail)) {
$requirements['smtp_phpmailer'] = [
'title' => (string) t('SMTP: PHPMailer Library'),
'value' => (string) t('Missing'),
'severity' => REQUIREMENT_ERROR,
'description' => t('PHPMailer is Required for SMTP to function.'),
];
// If PHPMailer is not found, SMTP should not be set as the mail system.
_disable_smtp();
return $requirements;
}
else {
$required_version = '6.1.7';
$installed_version = $mail::VERSION;
$reflector = new \ReflectionClass('\\PHPMailer\\PHPMailer\\PHPMailer');
$requirements['smtp_phpmailer'] = [
'title' => (string) t('SMTP: PHPMailer library'),
'value' => $installed_version,
'description' => t('PHPMailer is located at %path', [
'%path' => $reflector
->getFileName(),
]),
];
if (!version_compare($installed_version, $required_version, '>=')) {
$requirements['smtp_phpmailer']['severity'] = REQUIREMENT_ERROR;
$requirements['smtp_phpmailer']['description'] = (string) t("PHPMailer library @version or higher is required. Please install a newer version by executing 'composer update' in your site's root directory.", [
'@version' => $required_version,
]);
// If incorrect version, SMTP should not be set as the mail system.
_disable_smtp();
}
else {
$requirements['smtp_phpmailer']['severity'] = REQUIREMENT_INFO;
/** @var \Drupal\smtp\ConnectionTester\ConnectionTester $tester */
$tester = \Drupal::service('smtp.connection_tester');
$tester
->testConnection();
$requirements = array_merge($requirements, $tester
->hookRequirements($phase));
}
}
}
return $requirements;
}