[Mate][Symfony] Add MailerCollectorFormatter for Symfony profiler

This commit is contained in:
Johannes Wachter
2026-02-19 21:45:57 +01:00
committed by Oskar Stark
parent 7d7c3cc075
commit 1116f3d748
8 changed files with 149 additions and 0 deletions

4
.env
View File

@@ -26,3 +26,7 @@ HUGGINGFACE_API_KEY=
###> symfony/ai-open-ai-platform ###
OPENAI_API_KEY=
###< symfony/ai-open-ai-platform ###
###> symfony/mailer ###
MAILER_DSN=null://null
###< symfony/mailer ###

View File

@@ -25,4 +25,42 @@
}
}
}
.share-overlay {
position: fixed;
inset: 0;
display: none;
align-items: center;
justify-content: center;
padding: 24px;
background: rgba(20, 30, 20, 0.55);
z-index: 1055;
}
.share-overlay.is-open {
display: flex;
}
.share-panel {
position: relative;
width: min(520px, 92vw);
padding: 24px 24px 20px;
border-radius: 16px;
background: #ffffff;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.share-close {
position: absolute;
top: 10px;
right: 12px;
width: 32px;
height: 32px;
border-radius: 16px;
text-align: center;
line-height: 32px;
text-decoration: none;
color: #2f3f2f;
background: #f0f4ef;
}
}

12
compose.override.yaml Normal file
View File

@@ -0,0 +1,12 @@
services:
###> symfony/mailer ###
mailer:
image: axllent/mailpit
ports:
- "1025"
- "8025"
environment:
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
###< symfony/mailer ###

View File

@@ -31,6 +31,7 @@
"symfony/form": "^8.0",
"symfony/framework-bundle": "^8.0",
"symfony/http-client": "^8.0",
"symfony/mailer": "^8.0",
"symfony/mcp-bundle": "^0.5",
"symfony/mime": "^8.0",
"symfony/monolog-bundle": "^4.0",

View File

@@ -0,0 +1,3 @@
framework:
mailer:
dsn: '%env(MAILER_DSN)%'

View File

@@ -12,6 +12,8 @@
namespace App\Recipe;
use App\Recipe\Data\Recipe;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
@@ -25,8 +27,15 @@ final class TwigComponent
#[LiveProp(writable: true)]
public ?string $message = null;
#[LiveProp(writable: true)]
public ?string $shareEmail = null;
#[LiveProp]
public bool $shareOpen = false;
public function __construct(
private readonly Chat $chat,
private readonly MailerInterface $mailer,
) {
}
@@ -56,4 +65,46 @@ final class TwigComponent
{
$this->chat->reset();
}
#[LiveAction]
public function openShare(): void
{
$this->shareOpen = true;
}
#[LiveAction]
public function closeShare(): void
{
$this->shareOpen = false;
}
#[LiveAction]
public function share(): void
{
if (null === $this->shareEmail || '' === trim($this->shareEmail)) {
return;
}
if (false === filter_var($this->shareEmail, \FILTER_VALIDATE_EMAIL)) {
return;
}
$recipe = $this->getRecipe();
if (null === $recipe) {
return;
}
$body = $recipe->toString().\PHP_EOL.\PHP_EOL.'Generated by https://github.com/symfony/ai-demo';
$email = (new Email())
->from('noreply@symfony-ai.demo')
->to($this->shareEmail)
->subject(\sprintf('Recipe: %s', $recipe->name))
->text($body);
$this->mailer->send($email);
$this->shareOpen = false;
$this->shareEmail = null;
}
}

View File

@@ -215,6 +215,18 @@
"src/Kernel.php"
]
},
"symfony/mailer": {
"version": "8.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "4.3",
"ref": "09051cfde49476e3c12cd3a0e44289ace1c75a4f"
},
"files": [
"config/packages/mailer.yaml"
]
},
"symfony/mcp-bundle": {
"version": "dev-main"
},

View File

@@ -72,6 +72,13 @@
</div>
{% endfor %}
</div>
<div class="mt-4 border-top pt-3 d-flex align-items-center justify-content-between">
<div class="fw-semibold text-muted">Share this recipe</div>
<button class="btn btn-outline-secondary" {{ live_action('openShare') }}>
{{ ux_icon('mdi:email-send', { height: '20px', width: '20px', class: 'me-1' }) }}
Share
</button>
</div>
</div>
</div>
</div>
@@ -92,6 +99,27 @@
</div>
</div>
</div>
<div id="recipe-share-overlay" class="share-overlay {{ this.shareOpen ? 'is-open' : '' }}">
<div class="share-panel">
<button class="share-close" {{ live_action('closeShare') }} aria-label="Close">×</button>
<h4 class="mb-2">
{{ ux_icon('mdi:email-send', { height: '22px', width: '22px', class: 'me-2' }) }}
Share this recipe
</h4>
<p class="text-muted mb-3">Send the recipe to an email address.</p>
<form class="input-group" {{ live_action('share:prevent') }}>
<input
type="email"
class="form-control"
placeholder="Email address"
data-model="shareEmail"
>
<button class="btn btn-outline-secondary">
Send
</button>
</form>
</div>
</div>
<div class="card-footer p-2">
<form class="input-group" {{ live_action('submit:prevent') }}>
<input autofocus id="chat-message"