From 37206e0e7c580f62d0118b3ae8b4e3389e3d7fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C4=8Conka?= Date: Mon, 6 Apr 2015 19:15:01 +0200 Subject: [PATCH] Logger: added fromEmail option to set From header [Closes #109] Useful for hostings where From email headers in php mail() are restricted to concrete ones. --- src/Bridges/Nette/TracyExtension.php | 6 ++++-- src/Tracy/Logger.php | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Bridges/Nette/TracyExtension.php b/src/Bridges/Nette/TracyExtension.php index b32e2c9ad..0ea5dd7b2 100644 --- a/src/Bridges/Nette/TracyExtension.php +++ b/src/Bridges/Nette/TracyExtension.php @@ -19,6 +19,7 @@ class TracyExtension extends Nette\DI\CompilerExtension { public $defaults = array( 'email' => NULL, + 'fromEmail' => NULL, 'logSeverity' => NULL, 'editor' => NULL, 'browser' => NULL, @@ -68,9 +69,10 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) unset($options['bar'], $options['blueScreen']); foreach ($options as $key => $value) { if ($value !== NULL) { + $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key; $initialize->addBody($container->formatPhp( - 'Tracy\Debugger::$? = ?;', - Nette\DI\Compiler::filterArguments(array($key, $value)) + 'Tracy\Debugger::' . $key . ' = ?;', + Nette\DI\Compiler::filterArguments(array($value)) )); } } diff --git a/src/Tracy/Logger.php b/src/Tracy/Logger.php index 742b19c1f..363f2f921 100644 --- a/src/Tracy/Logger.php +++ b/src/Tracy/Logger.php @@ -23,6 +23,9 @@ class Logger implements ILogger /** @var string|array email or emails to which send error notifications */ public $email; + /** @var string sender of email notifications */ + public $fromEmail; + /** @var mixed interval for sending email is 2 days */ public $emailSnooze = '2 days'; @@ -183,7 +186,7 @@ public function defaultMailer($message, $email) array("\n", PHP_EOL), array( 'headers' => implode("\n", array( - "From: noreply@$host", + "From: " . ($this->fromEmail ?: "noreply@$host"), 'X-Mailer: Tracy', 'Content-Type: text/plain; charset=UTF-8', 'Content-Transfer-Encoding: 8bit',