Slide 1

Slide 1 text

Fabien Potencier @fabpot in 2019

Slide 2

Slide 2 text

How many of are going
 to SymfonyCon Amsterdam?

Slide 3

Slide 3 text

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/

Slide 16

Slide 16 text

Symfony
 Components symfony/symfony

Slide 17

Slide 17 text

Symfony 2+/3+ Monolog Bundle SwiftMailer Bundle Polyfill Util Polyfill PHP 7.0 Polyfill PHP 5.6 Polyfill Mbstring Polyfill Intl ICU Polyfill APCu PHPUnit Bridge Debug Bundle Framework Bundle Security Bundle Twig Bundle WebProfiler Bundle WebServer Bundle Doctrine Bridge Monolog Bridge Twig Bridge Monolog Doctrine (11) SecurityChecker Generator Bundle ParamHandler FrameworkExtra Bundle Distribution Bundle Asset BrowserKit Cache ClassLoader Config Console CssSelector Debug DependencyInjection DomCrawler Dotenv EventDispatcher ExpressionLanguage Filesystem Finder Form HttpFoundation HttpKernel Inflector Intl Ldap OptionsResolver Process PropertyAccess PropertyInfo Routing Security Serializer Stopwatch Templating Translation Validator VarDumper WebLink Workflow Yaml 4 bridges 15 librairies 11 bundles 42 components SwiftMailer

Slide 18

Slide 18 text

Symfony 4+/5+ Polyfill Mbstring Framework Bundle Cache Config Debug DependencyInjection Dotenv EventDispatcher Filesystem Finder HttpFoundation HttpKernel Routing Yaml 0 bridges 1 library 1 bundle 13 components Flex

Slide 19

Slide 19 text

$ 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++

Slide 26

Slide 26 text

Never define
 your service again*

Slide 27

Slide 27 text

Maker
 Bundle Generator
 Bundle

Slide 28

Slide 28 text

$ ./bin/console list make Symfony Maker Bundle

Slide 29

Slide 29 text

$ ./bin/console make:controller DefaultController Symfony Maker Bundle

Slide 30

Slide 30 text

$ 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

Slide 43

Slide 43 text

$ composer req twig/inky-extension twig/cssinliner-extension Sending emails {% apply inky|inline_css(source("@zurb/stylesheets/main.css")) %}

Symfony Connect

Forgot Your Password?

It happens. Click the link below to reset it.

Reset Password

unsubscribe here.

{% endapply %}

Slide 44

Slide 44 text

I want to send rich and responsive emails
 from my controller
 via my provider's API

Slide 45

Slide 45 text

$ composer req mailgun-mailer MAILER_DSN=http://$MAILGUN_KEY:$MAILGUN_DOMAIN@mailgun Sending emails Amazon SES Google Gmail Mandrill Mailgun Postmark Sendgrid

Slide 46

Slide 46 text

I want to send rich and responsive emails
 from my controller
 via my provider's API
 asynchronously

Slide 47

Slide 47 text

$ composer req messenger framework: messenger: transports: email: "doctrine://default" routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ ./bin/console messenger:consume $ symfony run -d ./bin/console messenger:consume -vv Sending emails Go to the background

Slide 48

Slide 48 text

$ symfony server:status $ symfony server:log Sending emails

Slide 49

Slide 49 text

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

Slide 55

Slide 55 text

$ composer req symfony/sendgrid-mailer MAILER_DSN=http://key:domain@mailgun || http://key@sendgrid Sending emails

Slide 56

Slide 56 text

framework: messenger: transports: email: dsn: "%env(RABBITMQ_DSN)%" retry_strategy: max_retries: 3 routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email Sending emails

Slide 57

Slide 57 text

framework: messenger: failure_transport: failed transports: failed: 'doctrine://default?queue_name=failed' email: dsn: "%env(RABBITMQ_DSN)%" retry_strategy: max_retries: 3 routing: Symfony\Component\Mailer\Messenger\SendEmailMessage: email $ symfony server:log $ ./bin/console messenger:failed:show $ ./bin/console messenger:failed:retry Sending emails

Slide 58

Slide 58 text

Sending emails

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

$ symfony project:init $ symfony deploy $ symfony log --worker=send_emails all Sending emails rabbitmq: type: rabbitmq:3.7 disk: 1500 .symfony/services.yaml .symfony.cloud.yaml runtime: extensions: [ "amqp" ] relationships: rabbitmq: "rabbitmq:rabbitmq" workers: send_emails: commands: start: | set -x -e (>&2 symfony-deploy) bin/console messenger:consume -vv email Production ready

Slide 61

Slide 61 text

$ 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

Slide 68

Slide 68 text

... to be continued

Slide 69

Slide 69 text

Thank you and see you soon!