Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Laravel 9 Support #1170

Merged
merged 4 commits into from Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Expand Up @@ -21,7 +21,12 @@ jobs:
fail-fast: true
matrix:
php: [7.3, 7.4, 8.0, 8.1]
laravel: [^8.0]
laravel: [^8.0, ^9.0]
exclude:
- php: 7.3
laravel: ^9.0
- php: 7.4
laravel: ^9.0

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -16,12 +16,12 @@
"require": {
"php": "^7.3|^8.0",
"ext-json": "*",
"laravel/framework": "^8.29",
"symfony/var-dumper": "^5.0"
"laravel/framework": "^8.29|^9.0",
"symfony/var-dumper": "^5.0|^6.0"
},
"require-dev": {
"ext-gd": "*",
"orchestra/testbench": "^6.0"
"orchestra/testbench": "^6.0|^7.0"
},
"autoload": {
"psr-4": {
Expand Down
37 changes: 31 additions & 6 deletions src/Watchers/MailWatcher.php
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Mail\Events\MessageSent;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Part\AbstractPart;

class MailWatcher extends Watcher
{
Expand All @@ -31,16 +33,18 @@ public function recordMail(MessageSent $event)
return;
}

$body = $event->message->getBody();

Telescope::recordMail(IncomingEntry::make([
'mailable' => $this->getMailable($event),
'queued' => $this->getQueuedStatus($event),
'from' => $event->message->getFrom(),
'replyTo' => $event->message->getReplyTo(),
'to' => $event->message->getTo(),
'cc' => $event->message->getCc(),
'bcc' => $event->message->getBcc(),
'from' => $this->formatAddresses($event->message->getFrom()),
'replyTo' => $this->formatAddresses($event->message->getReplyTo()),
'to' => $this->formatAddresses($event->message->getTo()),
'cc' => $this->formatAddresses($event->message->getCc()),
'bcc' => $this->formatAddresses($event->message->getBcc()),
'subject' => $event->message->getSubject(),
'html' => $event->message->getBody(),
'html' => $body instanceof AbstractPart ? $body->bodyToString() : $body,
'raw' => $event->message->toString(),
])->tags($this->tags($event->message, $event->data)));
}
Expand Down Expand Up @@ -75,6 +79,27 @@ protected function getQueuedStatus($event)
return $event->data['__telescope_queued'] ?? false;
}

/**
* Convert the given addresses into a readable format.
*
* @param array|null $addresses
* @return array|null
*/
protected function formatAddresses(?array $addresses)
{
if (is_null($addresses)) {
return null;
}

return collect($addresses)->flatMap(function ($address, $key) {
if ($address instanceof Address) {
return [$address->getAddress() => $address->getName()];
}

return [$key => $address];
})->all();
}

/**
* Extract the tags from the message.
*
Expand Down