Join us for a week of Symfony,
November 19-23, at the Beurs
van Berlage:
• November 19-20: 2-day pre-
conference workshops
• November 21-22: 2-day
conference (3 tracks and 1
Unconference)
• November 23: 1-day Hackday
Get an exclusive 10% discount on
your registration using the code:
SFC19PHPAMS
Code available until June 26 2019
amsterdam2019.symfony.com
Slide 4
Slide 4 text
Come to meet the
international Symfony
and PHP communities!
Become a Sponsor of the
event! Support the
framework and get
visibility for your
company during the
conference!
Contact us:
[email protected]
1,000+ attendees and 30+
speakers will be there during
our 2-day conference!
Slide 5
Slide 5 text
Which
Symfony version(s)
are you using?
1.x? 2.x? 3.x? 4.x?
Slide 6
Slide 6 text
What is Symfony 4?
A new developer experience
On a rock solid foundation
From micro-style to monolith and prototypes
Slide 7
Slide 7 text
Wired?
Tired?
or
Slide 8
Slide 8 text
Symfony
Encore
Webpack
Assetic
Slide 9
Slide 9 text
Symfony
Local Web Server
Built-in
PHP server
Slide 10
Slide 10 text
Symfony Local Web Server
$ symfony server:start -d
# open in the browser
$ symfony open:local
# tail the logs
$ symfony server:log
Slide 11
Slide 11 text
• PHP-FPM (concurrent requests)
• HTTP 2
• TLS
• Local domain names
• No dependencies / single binary (MacOS, Linux, and Windows)
• Manages background commands (Encore, Messenger, ...)
• Consolidated logs (PHP
, Web server, app, background commands)
• Docker integration (and SymfonyCloud)
• Multiple versions of PHP
• HTTP Link/pre-load/push support
Symfony
Local Web Server
Slide 12
Slide 12 text
12
https://symfony.com/download
Slide 13
Slide 13 text
$ symfony new demo
$ symfony new demo --cloud --debug
# Want to try Symfony 5.0 (dev version)?
$ symfony new demo --version=dev-master
Creating a new project
Slide 14
Slide 14 text
Symfony
CLI
SensioLabs
Security
Checker
Slide 15
Slide 15 text
$ symfony security:check
Does not call
https://security.symfony.com/
Clones and caches
https://github.com/FriendsOfPHP/security-advisories/
$ symfony new demo
# Forms are ❌ disabled as symfony/form is not installed
$ composer req form
# Forms are automatically ✅ enabled as symfony/form is installed
+ Auto-configuration
+ No manual changes
+ Better performance
Slide 20
Slide 20 text
Third-party
Bundles
with recipes
Application
Bundles
Slide 21
Slide 21 text
$ cat src/Controller/DefaultController.php
App vs Bundles
src/ is about YOUR code
Slide 22
Slide 22 text
Environment
Variables
Class Constants
Parameters n/a
Slide 23
Slide 23 text
Parameter Class constant Environment variable
Can be provided
by a third party ("standard")
❌ ❌ ✅
Can be changed
without cache:clear
❌ ❌ ✅
Easy to use in code ❌ ✅
Can be changed
without redeploy
❌ ✅
Can be different
in dev and prod
✅ ❌ ✅
Can be stored
outside of a Git repo
✅ ❌ ✅
Rich type support via processors
Example
Configure
behavior
Configure
behavior
Configure
infrastructure
Slide 24
Slide 24 text
Container
Auto-discovery
Auto-configuration
Auto-wiring
Service
Configuration
Slide 25
Slide 25 text
$ composer req twig
Adding Twig
+ Controller as a service
+ No manual changes
+ No configuration
+ Auto-wiring
Productivity++
$ cat src/Controller/DefaultController.php
Symfony Maker Bundle
Annotations
Everything in one file
Slide 31
Slide 31 text
Adding a Twig Extension
Where do I store
the Twig extension
class?
Which file do I
need to change to
register it?
Which tag do I need
to use?
How do I declare a
tag in YAML?
Which interface/class
do I need to implement/
extend? It’s too complex. What
about doing it the dirty
way and do it in the
controller instead?
hmm, ok
Slide 32
Slide 32 text
$ ./bin/console make:twig-extension
Adding a Twig Extension
Add your logic in the
generated class…
DONE!
Slide 33
Slide 33 text
Full Automation works for…
• Twig extensions
• Event listeners
• Doctrine entities/repositories
• Commands
• Voters
• Registration form system
• …
Slide 34
Slide 34 text
Twig
Templates
PHP
Templates
Slide 35
Slide 35 text
You can use PHP templates
But Twig benefits
from a fully maintained integration
Slide 36
Slide 36 text
Symfony
Mailer
Swiftmailer
Slide 37
Slide 37 text
A great example of
how we leverage
the "new" Symfony infrastructure
Slide 38
Slide 38 text
I want to send emails
from my controller
Slide 39
Slide 39 text
$ composer req symfony/mailer
Sending emails
use Symfony\Component\Mailer\MailerInterface;
public function index(MailerInterface $mailer)
{
$mailer->send(
(new Email())
->from('[email protected]')
->to('[email protected]')
->subject('Some subject')
->text('Some text...')
);
MAILER_DSN=smtp://localhost
+ No configuration
+ No manual changes
+ Auto-wiring
+ Env vars
Slide 40
Slide 40 text
I want to send rich emails
from my controller
Slide 41
Slide 41 text
Sending emails
use Symfony\Component\Mailer\MailerInterface;
public function index(MailerInterface $mailer)
{
$mailer->send(
(new TemplatedEmail())
->from('[email protected]')
->to('[email protected]')
->subject('Some subject')
->htmlTemplate('@emails/welcome.html.twig')
->context([
'city' => 'Tunis'
])
);
Slide 42
Slide 42 text
I want to send rich and responsive emails
from my controller
I want to send rich and responsive emails
from my controller
via my provider's API
asynchronously with AMQP
Slide 50
Slide 50 text
At this point, think about
how you would do it
with Symfony 3.4
Here, we have not written
a single line of code
and barely changed the configuration
Slide 51
Slide 51 text
We are only using Symfony components
Slide 52
Slide 52 text
I want to send rich and responsive emails
from my controller
via my provider's API
asynchronously with AMQP
Slide 53
Slide 53 text
framework:
messenger:
transports:
email: "%env(RABBITMQ_DSN)%"
routing:
Symfony\Component\Mailer\Messenger\SendEmailMessage: email
$ docker-compose up -d
Sending emails
rabbitmq:
image: rabbitmq
ports:
- 5672
docker-compose.yml
Symfony Local Web Server
Env vars "auto-wiring"
Local port is random
Slide 54
Slide 54 text
I want to send rich and responsive emails
from my controller
via my provider's API
asynchronously with AMQP
and manage failures gracefully
I want to send rich and responsive emails
from my controller
via my provider's API
asynchronously with AMQP
and manage failures gracefully
without Docker
$ symfony tunnel:open
Sending emails
Symfony Local Web Server
Env vars "auto-wiring"
.symfony.cloud.yaml
relationships:
rabbitmq: "rabbitmq:rabbitmq"
Development ready
framework:
messenger:
transports:
email: "%env(RABBITMQ_DSN)%"
Slide 62
Slide 62 text
Experience
The new
Components: http-client, messenger, mailer, container, ...
Concepts: Flex, auto-configuration, env vars, ...
Tools: Symfony CLI, SymfonyCloud, Docker
Slide 63
Slide 63 text
is a fantastic set of low-level building blocks
that you can assemble to develop
powerful high-level features easily
Slide 64
Slide 64 text
What about the future?
Nobody knows, it depends on you
... so, what have you done so far for Symfony 4.4?
Slide 65
Slide 65 text
HTTP errors without Twig
Important for API-only applications
Slide 66
Slide 66 text
PHP 7.4 preload support
Performance FTW
Slide 67
Slide 67 text
A better Security component?
https://github.com/symfony/symfony/issues/30914
https://github.com/symfony/symfony/issues/30765