Skip to content

Commit

Permalink
Merge 6a92e44 into 412e5ec
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 20, 2020
2 parents 412e5ec + 6a92e44 commit abe4bc9
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 11 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -32,7 +32,7 @@ Features
- [x] Provide request information ( http method, raw data, body data, query data, files data, cookie data, and ip address).
- [x] Send Mail
- [x] many receivers to listed configured email
- [x] with include $_FILES into attachments on upload error.
- [x] with include $_FILES into attachments on upload error (configurable to be included or not).

Installation
------------
Expand Down Expand Up @@ -286,6 +286,9 @@ json
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
3 changes: 3 additions & 0 deletions config/error-hero-module.local.php.dist
Expand Up @@ -124,6 +124,9 @@ json
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
3 changes: 3 additions & 0 deletions config/mezzio-error-hero-module.local.php.dist
Expand Up @@ -129,6 +129,9 @@ json
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -93,6 +93,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -94,6 +94,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -96,6 +96,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -87,6 +87,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -94,6 +94,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -91,6 +91,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
Expand Up @@ -93,6 +93,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
// no email in the list
],
Expand Down
Expand Up @@ -93,6 +93,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
3 changes: 3 additions & 0 deletions spec/Fixture/config/autoload/error-hero-module.local.php
Expand Up @@ -83,6 +83,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
3 changes: 3 additions & 0 deletions spec/Handler/LoggingFactorySpec.php
Expand Up @@ -89,6 +89,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
3 changes: 3 additions & 0 deletions spec/Handler/LoggingSpec.php
Expand Up @@ -61,6 +61,9 @@
// email sender
'email-from' => 'Sender Name <sender@host.com>',

// to include or not $_FILES on send mail
'include-files-to-attachments' => true,

'email-to-send' => [
'developer1@foo.com',
'developer2@foo.com',
Expand Down
25 changes: 16 additions & 9 deletions src/Handler/Logging.php
Expand Up @@ -52,20 +52,25 @@ class Logging
/** @var string */
private $emailSender;

/** @var bool */
private $includeFilesToAttachments;

public function __construct(
Logger $logger,
array $errorHeroModuleLocalConfig,
array $logWritersConfig,
?Message $mailMessageService = null,
?TransportInterface $mailMessageTransport = null
?TransportInterface $mailMessageTransport = null,
bool $includeFilesToAttachments = true
) {
$this->logger = $logger;
$this->configLoggingSettings = $errorHeroModuleLocalConfig['logging-settings'];
$this->logWritersConfig = $logWritersConfig;
$this->mailMessageService = $mailMessageService;
$this->mailMessageTransport = $mailMessageTransport;
$this->emailReceivers = $errorHeroModuleLocalConfig['email-notification-settings']['email-to-send'];
$this->emailSender = $errorHeroModuleLocalConfig['email-notification-settings']['email-from'];
$this->logger = $logger;
$this->configLoggingSettings = $errorHeroModuleLocalConfig['logging-settings'];
$this->logWritersConfig = $logWritersConfig;
$this->mailMessageService = $mailMessageService;
$this->mailMessageTransport = $mailMessageTransport;
$this->emailReceivers = $errorHeroModuleLocalConfig['email-notification-settings']['email-to-send'];
$this->emailSender = $errorHeroModuleLocalConfig['email-notification-settings']['email-from'];
$this->includeFilesToAttachments = $includeFilesToAttachments;
}

/**
Expand Down Expand Up @@ -113,7 +118,9 @@ private function getRequestData(RequestInterface $request): array
$request_method = $request->getMethod();
$body_data = $request->getPost()->toArray();
$raw_data = str_replace(PHP_EOL, '', $request->getContent());
$files_data = $request->getFiles()->toArray();
$files_data = $this->includeFilesToAttachments
? $request->getFiles()->toArray()
: [];
$cookie = $request->getCookie();
$cookie_data = $cookie instanceof Cookie
? $cookie->getArrayCopy()
Expand Down
5 changes: 4 additions & 1 deletion src/Handler/LoggingFactory.php
Expand Up @@ -47,12 +47,15 @@ public function __invoke(ContainerInterface $container): Logging
}
}

$includeFilesToAttachments = $mailConfig['include-files-to-attachments'] ?? true;

return new Logging(
$errorHeroModuleLogger,
$errorHeroModuleLocalConfig,
$logWritersConfig,
$mailMessageService,
$mailMessageTransport
$mailMessageTransport,
$includeFilesToAttachments
);
}
}

0 comments on commit abe4bc9

Please sign in to comment.