class PrintEngineException in Entity Print 8.2
The exception thrown when a implementation fails to generate a document.
Hierarchy
- class \Drupal\entity_print\PrintEngineException extends \Drupal\entity_print\Exception uses StringTranslationTrait
Expanded class hierarchy of PrintEngineException
11 files declare their use of PrintEngineException
- DomPdf.php in src/
Plugin/ EntityPrint/ PrintEngine/ DomPdf.php - EntityPrintPluginManager.php in src/
Plugin/ EntityPrintPluginManager.php - EntityPrintPluginManagerTest.php in tests/
src/ Kernel/ EntityPrintPluginManagerTest.php - PhpWkhtmlToPdf.php in src/
Plugin/ EntityPrint/ PrintEngine/ PhpWkhtmlToPdf.php - PrintDownload.php in src/
Plugin/ Action/ PrintDownload.php
File
- src/
PrintEngineException.php, line 12
Namespace
Drupal\entity_printView source
class PrintEngineException extends \Exception {
use StringTranslationTrait;
/**
* Gets a pretty version of the exception message.
*
* @return string
* The pretty message.
*/
public function getPrettyMessage() {
// Build a safe markup string using Xss::filter() so that the instructions
// for installing dependencies can contain quotes.
$default_message = (string) $this
->t('Error generating document: @message', [
'@message' => new FormattableMarkup(Xss::filter($this
->getMessage()), []),
]);
return $this
->refineMessage($this
->getMessage()) ?: $default_message;
}
/**
* Attempt to refine the error message to help the user.
*
* @param string $message
* The error message.
*
* @return string
* The parsed error message, possibly more refined.
*/
protected function refineMessage($message) {
if ($this
->isAuthFailure($message)) {
return $this
->getAuthFailureMessage();
}
return '';
}
/**
* Check if this message looks like an authorisation failure.
*
* @param string $message
* The error message.
*
* @return bool
* TRUE if it was an auth failure otherwise FALSE.
*/
protected function isAuthFailure($message) {
$regexs = [
// Dompdf.
'/401 Unauthorized/',
// Wkhtmltopdf.
'/AuthenticationRequiredError/',
];
return $this
->evalulateRegex($regexs, $message);
}
/**
* Gets a new auth failure message.
*
* @return string
* The pretty version of the auth failure message.
*/
protected function getAuthFailureMessage() {
return $this
->t('Authorisation failed, are your resources behind HTTP authentication? Check the admin page to set credentials.');
}
/**
* Evaluates our patterns against the subject.
*
* @param array $patterns
* An array of regular expressions to check.
* @param string $subject
* The subject to check against.
*
* @return bool
* TRUE if anyone of the patterns match otherwise FALSE.
*/
protected function evalulateRegex(array $patterns, $subject) {
foreach ($patterns as $pattern) {
if (preg_match($pattern, $subject, $matches)) {
return TRUE;
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrintEngineException:: |
protected | function | Evaluates our patterns against the subject. | |
PrintEngineException:: |
protected | function | Gets a new auth failure message. | |
PrintEngineException:: |
public | function | Gets a pretty version of the exception message. | |
PrintEngineException:: |
protected | function | Check if this message looks like an authorisation failure. | |
PrintEngineException:: |
protected | function | Attempt to refine the error message to help the user. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |