Skip to content

Commit edb5fed

Browse files
committed
feature #36479 [Notifier][WebProfilerBundle][FrameworkBundle] Add notifier section to profiler (jschaedl)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [Notifier][WebProfilerBundle][FrameworkBundle] Add notifier section to profiler | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | - <!-- required for new features --> This is the first iteration of adding a profiler panel for the new Notifier component: WebProfiler Toolbar: ![Screenshot 2020-10-02 at 10 26 35](https://user-images.githubusercontent.com/1880467/94903474-28bece00-049a-11eb-945c-d6ce047b35e8.png) WebProfiler Notifier Panel: ![Screenshot 2020-10-02 at 10 28 19](https://user-images.githubusercontent.com/1880467/94903594-5277f500-049a-11eb-8c1e-27e6ec87a51c.png) ![Screenshot 2020-10-02 at 10 28 29](https://user-images.githubusercontent.com/1880467/94903591-51df5e80-049a-11eb-935a-9ba130ef69f0.png) ![Screenshot 2020-10-02 at 10 28 35](https://user-images.githubusercontent.com/1880467/94903589-5146c800-049a-11eb-8a69-28d362ef6640.png) ![Screenshot 2020-10-02 at 10 28 42](https://user-images.githubusercontent.com/1880467/94903586-50159b00-049a-11eb-97bd-382a823087a6.png) An example project can to test the new profiler panel can be found here: https://github.com/jschaedl/notifier-profiler-integration Commits ------- f39e74b [Notifier][WebProfilerBundle][FrameworkBundle] Add notifier section to profiler
2 parents f8212cc + f39e74b commit edb5fed

File tree

8 files changed

+181
-4
lines changed

8 files changed

+181
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_debug.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
$container->services()
1818
->set('notifier.data_collector', NotificationDataCollector::class)
1919
->args([service('notifier.logger_notification_listener')])
20+
->tag('data_collector', ['template' => '@WebProfiler/Collector/notifier.html.twig', 'id' => 'notifier'])
2021
;
2122
};
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
2+
3+
{% block toolbar %}
4+
{% set events = collector.events %}
5+
6+
{% if events.messages|length %}
7+
{% set icon %}
8+
{% include('@WebProfiler/Icon/mailer.svg') %}
9+
<span class="sf-toolbar-value">{{ events.messages|length }}</span>
10+
{% endset %}
11+
12+
{% set text %}
13+
<div class="sf-toolbar-info-piece">
14+
<b>Sent notifications</b>
15+
<span class="sf-toolbar-status">{{ events.messages|length }}</span>
16+
</div>
17+
18+
{% for transport in events.transports %}
19+
<div class="sf-toolbar-info-piece">
20+
<b>{{ transport }}</b>
21+
<span class="sf-toolbar-status">{{ events.messages(transport)|length }}</span>
22+
</div>
23+
{% endfor %}
24+
{% endset %}
25+
26+
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', { 'link': profiler_url }) }}
27+
{% endif %}
28+
{% endblock %}
29+
30+
{% block head %}
31+
{{ parent() }}
32+
<style type="text/css">
33+
/* utility classes */
34+
.m-t-0 { margin-top: 0 !important; }
35+
.m-t-10 { margin-top: 10px !important; }
36+
37+
/* basic grid */
38+
.row {
39+
display: flex;
40+
flex-wrap: wrap;
41+
margin-right: -15px;
42+
margin-left: -15px;
43+
}
44+
.col {
45+
flex-basis: 0;
46+
flex-grow: 1;
47+
max-width: 100%;
48+
position: relative;
49+
width: 100%;
50+
min-height: 1px;
51+
padding-right: 15px;
52+
padding-left: 15px;
53+
}
54+
.col-4 {
55+
flex: 0 0 33.333333%;
56+
max-width: 33.333333%;
57+
}
58+
59+
/* small tabs */
60+
.sf-tabs-sm .tab-navigation li {
61+
font-size: 14px;
62+
padding: .3em .5em;
63+
}
64+
</style>
65+
{% endblock %}
66+
67+
{% block menu %}
68+
{% set events = collector.events %}
69+
70+
<span class="label {{ events.messages|length ? '' : 'disabled' }}">
71+
<span class="icon">{{ include('@WebProfiler/Icon/mailer.svg') }}</span>
72+
73+
<strong>Notifications</strong>
74+
{% if events.messages|length > 0 %}
75+
<span class="count">
76+
<span>{{ events.messages|length }}</span>
77+
</span>
78+
{% endif %}
79+
</span>
80+
{% endblock %}
81+
82+
{% block panel %}
83+
{% set events = collector.events %}
84+
85+
<h2>Notifications</h2>
86+
87+
{% if not events.messages|length %}
88+
<div class="empty">
89+
<p>No notifications were sent.</p>
90+
</div>
91+
{% endif %}
92+
93+
<div class="metrics">
94+
{% for transport in events.transports %}
95+
<div class="metric">
96+
<span class="value">{{ events.messages(transport)|length }}</span>
97+
<span class="label">{{ transport }}</span>
98+
</div>
99+
{% endfor %}
100+
</div>
101+
102+
{% for transport in events.transports %}
103+
<h3>{{ transport }}</h3>
104+
105+
<div class="card-block">
106+
<div class="sf-tabs sf-tabs-sm">
107+
{% for event in events.events(transport) %}
108+
{% set message = event.message %}
109+
<div class="tab">
110+
<h3 class="tab-title">Message #{{ loop.index }} <small>({{ event.isQueued() ? 'queued' : 'sent' }})</small></h3>
111+
<div class="tab-content">
112+
<div class="card">
113+
<div class="card-block">
114+
<span class="label">Subject</span>
115+
<h2 class="m-t-10">{{ message.getSubject() ?? '(empty)' }}</h2>
116+
</div>
117+
{% if message.getNotification is defined %}
118+
<div class="card-block">
119+
<div class="row">
120+
<div class="col">
121+
<span class="label">Content</span>
122+
<pre class="prewrap">{{ message.getNotification().getContent() ?? '(empty)' }}</pre>
123+
<span class="label">Importance</span>
124+
<pre class="prewrap">{{ message.getNotification().getImportance() }}</pre>
125+
</div>
126+
</div>
127+
</div>
128+
{% endif %}
129+
<div class="card-block">
130+
<div class="sf-tabs sf-tabs-sm">
131+
{% if message.getNotification is defined %}
132+
<div class="tab">
133+
<h3 class="tab-title">Notification</h3>
134+
{% set notification = event.message.getNotification() %}
135+
<div class="tab-content">
136+
<pre class="prewrap" style="max-height: 600px">
137+
{{- 'Subject: ' ~ notification.getSubject() }}<br/>
138+
{{- 'Content: ' ~ notification.getContent() }}<br/>
139+
{{- 'Importance: ' ~ notification.getImportance() }}<br/>
140+
{{- 'Emoji: ' ~ (notification.getEmoji() is empty ? '(empty)' : notification.getEmoji()) }}<br/>
141+
{{- 'Exception: ' ~ notification.getException() ?? '(empty)' }}<br/>
142+
{{- 'ExceptionAsString: ' ~ (notification.getExceptionAsString() is empty ? '(empty)' : notification.getExceptionAsString()) }}
143+
</pre>
144+
</div>
145+
</div>
146+
{% endif %}
147+
<div class="tab">
148+
<h3 class="tab-title">Message Options</h3>
149+
<div class="tab-content">
150+
<pre class="prewrap" style="max-height: 600px">
151+
{%- if message.getOptions() is null %}
152+
{{- '(empty)' }}
153+
{%- else %}
154+
{{- message.getOptions()|json_encode(constant('JSON_PRETTY_PRINT')) }}
155+
{%- endif %}
156+
</pre>
157+
</div>
158+
</div>
159+
</div>
160+
</div>
161+
</div>
162+
</div>
163+
</div>
164+
{% endfor %}
165+
</div>
166+
</div>
167+
{% endfor %}
168+
{% endblock %}

src/Symfony/Component/Notifier/Message/ChatMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getOptions(): ?MessageOptionsInterface
7777
/**
7878
* @return $this
7979
*/
80-
public function transport(?string $transport): self
80+
public function transport(?string $transport): MessageInterface
8181
{
8282
$this->transport = $transport;
8383

src/Symfony/Component/Notifier/Message/EmailMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function getOptions(): ?MessageOptionsInterface
102102
/**
103103
* @return $this
104104
*/
105-
public function transport(string $transport): self
105+
public function transport(string $transport): MessageInterface
106106
{
107107
if (!$this->message instanceof Email) {
108108
throw new LogicException('Cannot set a Transport on a RawMessage instance.');

src/Symfony/Component/Notifier/Message/MessageInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ public function getSubject(): string;
2525
public function getOptions(): ?MessageOptionsInterface;
2626

2727
public function getTransport(): ?string;
28+
29+
public function transport(string $transport): self;
2830
}

src/Symfony/Component/Notifier/Message/SmsMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getSubject(): string
8383
/**
8484
* @return $this
8585
*/
86-
public function transport(string $transport): self
86+
public function transport(string $transport): MessageInterface
8787
{
8888
$this->transport = $transport;
8989

src/Symfony/Component/Notifier/Transport/NullTransport.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function __construct(EventDispatcherInterface $dispatcher = null)
3434

3535
public function send(MessageInterface $message): SentMessage
3636
{
37+
if (null === $message->getTransport()) {
38+
$message->transport((string) $this);
39+
}
40+
3741
if (null !== $this->dispatcher) {
3842
$this->dispatcher->dispatch(new MessageEvent($message));
3943
}

src/Symfony/Component/Notifier/Transport/Transports.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ public function supports(MessageInterface $message): bool
5555
public function send(MessageInterface $message): SentMessage
5656
{
5757
if (!$transport = $message->getTransport()) {
58-
foreach ($this->transports as $transport) {
58+
foreach ($this->transports as $transportName => $transport) {
5959
if ($transport->supports($message)) {
60+
$message->transport($transportName);
61+
6062
return $transport->send($message);
6163
}
6264
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy