2019-09-12 20:59:05 +00:00
---
title: Live Blogging From SymfonyLive London 2019
tags:
- conference
- symfony
- symfonylive
- php
---
Inspired by [Matt Stauffer ](https://twitter.com/stauffermatt )'s [live blogging of the keynote ](https://mattstauffer.com/blog/introducing-laravel-vapor ) at Laracon US, I’ m going to do the same for the sessions that I’ m attending at [SymfonyLive London 2019 ](https://london2019.live.symfony.com )...
2019-09-13 08:07:34 +00:00
## Keynote (Back to the basics)
2019-09-13 08:03:44 +00:00
2019-09-13 08:10:54 +00:00
**Embrace the Linux philosophy**
2019-09-13 08:11:22 +00:00
* How we grow the Symfony ecosystem. Built abstracts.
* HttpFoundation, HttpKernel
* Moved to infrastructure
2019-09-13 08:47:55 +00:00
* A few abstractions on top of PHP. Improved versions of PHP functions (`dump` and `var_dump` )
2019-09-13 08:11:22 +00:00
* Started a add higher level abstractions (e.g. Mailer), built on the lower ones.
2019-09-13 08:11:59 +00:00
* Recently worked on PHPUnit assertions. Mailer in Symony 4.4. Can test if an email is sent or queued
2019-09-13 08:47:14 +00:00
**Building flexible high-level abstractions on top of low-level ones**
2019-09-13 08:11:59 +00:00
2019-09-13 08:12:24 +00:00
### What's next?
2019-09-13 08:11:59 +00:00
2019-09-13 08:12:58 +00:00
* Mailer announced in London last year. New component.
2019-09-13 08:13:18 +00:00
* System emails? e.g. new customer, new invoice.
2019-09-13 08:13:58 +00:00
* Symfony Mailer = Built-in responsive, flexible, and generic system emails
2019-09-13 08:15:11 +00:00
- Twig with TwigExtraBundle
- Twig `inky-extra` package (Twig 1.12+)
- Zurb Foundation for Emails CSS stylesheet
- Twig `cssinliner-extra` package (Twig 1.12+)
- Optimised Twig layouts
2019-09-13 08:17:20 +00:00
* `SystemEmail` class extends templated email
2019-09-13 08:17:07 +00:00
* Can set importance,
2019-09-13 08:17:27 +00:00
* Customisable
2019-09-13 08:18:09 +00:00
* Always trying to keep flexible, so things can be overidden and customised
2019-09-13 08:18:33 +00:00
### Sending SMS messages
2019-09-13 08:18:57 +00:00
2019-09-13 08:19:13 +00:00
* new `Texter` and `SmsMessage` class for sending SMS messages
2019-09-13 08:19:31 +00:00
* Same abstraction as emails, but for SMS messages
2019-09-13 08:20:21 +00:00
* Based on HttpClient + Symfony Messenger and third-party providers (Twilio and Nexmo) `twilio://` and `nemxo://`
2019-09-13 08:21:44 +00:00
* Can set via transport `$sms->setTransport('nexmo')`
2019-09-13 08:27:51 +00:00
* Extend the `SystemEmail` and do what you want
2019-09-13 08:47:14 +00:00
* Failover
2019-09-13 08:28:44 +00:00
### Sending Messages
2019-09-13 08:28:56 +00:00
* Create `ChatMessage`
2019-09-13 08:29:03 +00:00
* Telegram and Slack
2019-09-13 08:29:56 +00:00
* `$message->setTransport('telegram')` , `$bus->dispatch($message)`
2019-09-13 08:47:14 +00:00
* Send to Slack **and** Telegram
* `SlackOptions` and `TelegramOptions` for adding emojis etc
* Common transport layer `TransportInterface` , `MessageInterface`
* Failover - e.g. if Twilio is down, send to Telegram
### New component - SymfonyNotifier
* Channels - email, SMS, chat
* Transport, slack, telegram, twilio
* Create a notification, arguments are message and transports (array)
* Receiver
* Customise notifications, `InvoiceNotification` extends `Notification` . `getChannels`
* Override default rendering
* `ChatNotificationInterface` - `asChatMessage()`
* Semantic configuration
* `composer req twilio-notifier telegram-notifier`
* Channels
- Mailer
- Chatter
- Texter
- Browser
- Pusher (iOS, Android, Desktop native notifications)
- Database (web notification centre)
- **A unified way to notify Users via a unified Transport layer**
* Each integration is only 40 lines of code
### What about a SystemNotification?
* Autoconfigured channels
* `new SystemNotification` , `Notifier::getSystemReceivers`
* Importance, automatically configures channels
* Different channels based on importance
* `ExceptionNotification` - get email with stack trace attached
Notifier
* send messages via a unified api
* send to one or many receivers
* Default configu or custom one
### How can we leverage this new infrastructure?
* `Monolog NotifierHandler` - triggered on `Error` level logs
* Uses notified channel configuration
* Converts Error level logs to importance levels
* Configurablelike other Notifications
* 40 lines of code
* Failed Messages Listener - 10 lines of glue code
* **Experimental component in 5.0**
* Can't in in 4.4 as it's a LTS version
* First time an experimental component is added
* Stable in 5.1
2019-09-13 09:07:53 +00:00
## Queues, busses and the Messenger component (Tobias Nyholm)
2019-09-13 09:09:05 +00:00
* Stack is top and buttom - Last-in, first-out
* Queue is back and front - last in, first out
2019-09-13 09:12:30 +00:00
### 2013
* Using Symfony, used 40 or 50 bundles in a project - too much information!
* Used to copy and paste, duplicate a lot of code
* Testing your controllers - controllers as services?
2019-09-13 09:12:44 +00:00
* Controllers are 'comfortable'
2019-09-13 09:13:46 +00:00
* Tried adding `CurrentUserProvider` service to core, should be passed as an argument. Cannot test.
2019-09-13 09:14:18 +00:00
* 'Having Symfony all over the place wasn't the best thing' - when to framework (Matthias Noback)
2019-09-13 09:15:44 +00:00
- Hexagonal architecture
- Keep your kernel away from infrastructure. Let the framework handle the infrastructure.
2019-09-13 09:18:18 +00:00
* Controller -> Command -> Command Bus -> `CommandHandler`
2019-09-13 09:17:33 +00:00
2019-09-13 09:22:33 +00:00
#### What did we win?
2019-09-13 09:18:14 +00:00
* Can leverage Middleware with a command bus
2019-09-13 09:18:51 +00:00
* Queues as a service (RabbitMQ)
2019-09-13 09:20:16 +00:00
* Work queue - one producer, multiple consumers
* Queues should be durable - messages are also stored on disk, consumers should acknowledge a message once a message is handled
2019-09-13 09:21:19 +00:00
* Publish/subscribe
- Producer -> Fanout/direct with routing (multiple queues) -> multiple consumers
2019-09-13 09:21:46 +00:00
* Topics - wildcards
2019-09-13 09:22:33 +00:00
### 2016
* New intern. Understand everything, 'just PHP'. Plain PHP application, not 'scary Symfony'
2019-09-13 09:25:37 +00:00
### Symfony Messenger
2019-09-13 09:29:16 +00:00
2019-09-13 09:22:33 +00:00
* `composer req symfony/messager` - best MessageBus implementation
2019-09-13 09:23:04 +00:00
* Message -> Message bus -> Message handler
2019-09-13 09:23:20 +00:00
* Message is a plain PHP class
2019-09-13 09:24:13 +00:00
* Handler is a normal PHP class which is invokable
2019-09-13 09:24:52 +00:00
* `messenger:message_hander` tag in config
* Autowire with `MessageHandlerInterface`
2019-09-13 09:26:45 +00:00
* What if it takes 20 seconds to send a message? Use asynchronous.
2019-09-13 09:27:40 +00:00
* Transports as middleware (needs sender, receiver, configurable with DSN, encode/decode). `MESSENGER_DSN` added to `.env`
2019-09-13 09:28:03 +00:00
* Start consumer with `bin/console messager:consume-messages` . Time limit with `--time-limit 300`
2019-09-13 09:29:10 +00:00
* PHP Enqueue - production ready, battle-tested messaging solution for PHP
2019-09-13 09:34:16 +00:00
### Issues
* Transformers, takes an object and transforms into an array - `FooTransformer implements TransformerInterface` .
2019-09-13 09:34:52 +00:00
* Don't break other apps by changing the payload.
2019-09-13 09:35:41 +00:00
### Multiple buses
2019-09-13 09:37:41 +00:00
* Command bus, query bus, event bus
* Separate actions from reactions
## Envelope
2019-09-13 09:38:15 +00:00
* Stamps for metadata