public function SecuritytxtSerializer::getSecuritytxtFile in Security.txt 8
Gets the body of a security.txt file.
Parameters
\Drupal\Core\Config\ImmutableConfig $settings: A 'securitytxt.settings' config instance.
Return value
string The body of a security.txt file.
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException When the security.txt file is disabled.
File
- src/
SecuritytxtSerializer.php, line 28
Class
- SecuritytxtSerializer
- Securitytxt serializer class.
Namespace
Drupal\securitytxtCode
public function getSecuritytxtFile(ImmutableConfig $settings) {
$enabled = $settings
->get('enabled');
$contact_email = $settings
->get('contact_email');
$contact_phone = $settings
->get('contact_phone');
$contact_url = $settings
->get('contact_url');
$encryption_key_url = $settings
->get('encryption_key_url');
$policy_url = $settings
->get('policy_url');
$acknowledgement_url = $settings
->get('acknowledgement_url');
$signature_url = Url::fromRoute('securitytxt.securitytxt_signature')
->setAbsolute()
->toString();
if ($enabled) {
$content = '';
if ($contact_email != '') {
$content .= 'Contact: ' . $contact_email . "\n";
}
if ($contact_phone) {
$content .= 'Contact: ' . $contact_phone . "\n";
}
if ($contact_url != '') {
$content .= 'Contact: ' . $contact_url . "\n";
}
if ($encryption_key_url != '') {
$content .= 'Encryption: ' . $encryption_key_url . "\n";
}
if ($policy_url != '') {
$content .= 'Policy: ' . $policy_url . "\n";
}
if ($acknowledgement_url != '') {
$content .= 'Acknowledgement: ' . $acknowledgement_url . "\n";
}
$content .= 'Signature: ' . $signature_url . "\n";
return $content;
}
else {
throw new NotFoundHttpException();
}
}