Fabien Potencier
@fabpot
Haveyouever

usedSymfony?
1.x? 2.x? 3.x? 4.x?
WhatisSymfony4?
Anewdeveloperexperience
Onarocksolidfoundation
Frommicro-styletomonolith
4
inaction…
5
$ symfony new demo
# Want to try Symfony 5.0 (dev version)?
$ symfony new demo --version=dev-master
7
symfony/skeleton
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/console": "*",
"symfony/dotenv": "*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "*",
"symfony/yaml": "*"
},
$ symfony new demo --version=dev-master --debug
Demo
$ symfony new demo --version=dev-master --debug
Demo
$ symfony new demo --version=dev-master --debug
Demo
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
$ symfony new demo --version=dev-master --debug
Demo
$ tree -I vendor
$ find . -type f | wc -l
Symfony 4 is lightweight
Only 16 files
vs 31 SE
3300 total
vs 8867 SE
-65%
New directory structure
• Less depth, easier to navigate
• Non-PHP files in their own directories
(assets/, templates/)
• Decoupled from Symfony (assets/, src/,
templates/, public/)
https://github.com/symfony/recipes/

tree/master/

symfony/framework-bundle/4.2
Demo
Recipesrepositories
https://github.com/symfony/recipes

CuratedrecipesbySymfonycoreteam

https://github.com/symfony/recipes-contrib

Opentoallcontributions
370+ recipes
$ composer show | wc -l
Demo
Only 25 deps
vs 38 + 50 = 88 SE
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 BundleDoctrine 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 bundles42 components
SwiftMailer
Symfony 4+
Polyfill Mbstring
Framework BundleCache
Config
Debug
DependencyInjection
Dotenv
EventDispatcher
Filesystem
Finder
HttpFoundation
HttpKernel
Routing
Yaml
0 bridges
1 library
1 bundle13 components
Flex
$ symfony server:start -d
$ symfony server:log
Demo
Demo
$ ./bin/console
Demo
15 commands
vs 57 SE
$ git init
$ git add .
$ git commit -a -m"init"
Demo
$ composer req maker
Demo
Aliases
• Shortcuts for common packages (log, behat,
phpunit, …)
• Optimized for Symfony Components (no need
to use the symfony/ prefix, just workflow, dom-crawler, …)
• Opinionated choices (admin, api, orm, mailer, test,
…)
Packs
• Bundle several dependencies into a
consistent set (debug, profiler, api, test, …)
$ composer req debug
Discover Aliases and Packs
https://flex.symfony.com/
$ composer req maker
$ git diff config/bundles.php
Symfony Maker Bundle
$ ./bin/console list make
Symfony Maker Bundle
$ ./bin/console make:controller
Symfony Maker Bundle
$ composer req annot
Symfony Maker Bundle
$ ./bin/console make:controller DefaultController
Symfony Maker Bundle
$ vim src/Controller/DefaultController.php
Symfony Maker Bundle
src/ is about YOUR code
Symfony4helpsyou

growyourapp

withease
$ composer req twig
Adding Twig
Neverdefine

yourserviceagain*
AddingaTwigExtension
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
$ ./bin/console make:twig-extension
Adding a Twig Extension
Add your logic in the
generated class…
DONE!
Full Automation works for…
• Twig extensions
• Event listeners
• Doctrine repositories
• Commands
• Voters
• Registration form system
• …
Beyond “Hello World”
• Defining some models via Doctrine
• Adding an API for my model
• Managing data with an admin
$ composer req orm admin api
Full stack really quick
$ composer req orm admin api
Full stack really quick
$ ./bin/console make:entity Product --api-resource
Full stack really quick
$ vim config/packages/easy_admin.yaml
Full stack really quick
$ vim .env
DATABASE_URL="sqlite:///%kernel.project_dir%/var/
data.db"
$ ./bin/console doctrine:database:create
$ ./bin/console doctrine:schema:update --force
Full stack really quick
Itworks!
One line config change
One annotation added
Typical features
to the next level
I want to send emails

from my controller
$ composer req symfony/mailer
Symfony Maker Bundle
use SymfonyComponentMailerMailerInterface;
public function index(MailerInterface $mailer)
{
$mailer->send(
(new Email())
->from('fabien@symfony.com')
->to('fabien@symfony.com')
->subject('Some subject')
->text('Some text...')
);
MAILER_DSN=smtp://localhost
I want to send rich emails

from my controller
Symfony Maker Bundle
use SymfonyComponentMailerMailerInterface;
public function index(MailerInterface $mailer)
{
$mailer->send(
(new TemplatedEmail())
->from('fabien@symfony.com')
->to('fabien@symfony.com')
->subject('Some subject')
->htmlTemplate('@emails/welcome.html.twig')
->context([
'city' => 'Tunis'
])
);
MAILER_DSN=smtp://localhost
I want to send rich and responsive emails

from my controller
$ composer req twig/inky-extension
Symfony Maker Bundle
MAILER_DSN=smtp://localhost
{% apply inky|inline_css(source("@zurb/stylesheets/main.css")) %}
<container>
<row class="header">
<columns>
<spacer size="16"></spacer>
<h4 class="text-center">Symfony Connect</h4>
</columns>
</row>
<row>
<columns>
<spacer size="32"></spacer>
<center><img width="100px" src="{{ email.image("@images/symfony.png") }}"></center>
<spacer size="16"></spacer>
<h1 class="text-center">Forgot Your Password?</h1>
<spacer size="16"></spacer>
<p class="text-center">It happens. Click the link below to reset it.</p>
<button class="large expand" href="#">Reset Password</button>
<hr/>
<p><small><center><a href="#">unsubscribe here</a>.</small></center></p>
</columns>
</row>
</container>
{% endapply %}
I want to send rich and responsive emails

from my controller

via my provider's API
$ composer req symfony/mailgun-mailer
MAILER_DSN=http://key:domain@mailgun
Symfony Maker Bundle
AmazonSES
GoogleGmail
Mandrill
Mailgun
Postmark
Sendgrid
I want to send rich and responsive emails

from my controller

via my provider's API

asynchronously
$ composer req messenger
framework:
messenger:
transports:
email: "doctrine://default"
routing:
SymfonyComponentMailerMessengerSendEmailMessage: email
$ ./bin/console messenger:consume
Symfony Maker Bundle
I want to send rich and responsive emails

from my controller

via my provider's API

asynchronously with AMQP
$ composer req messenger
framework:
messenger:
transports:
email: "amqp://guest:guest@localhost:5672/%2f/messages"
routing:
SymfonyComponentMailerMessengerSendEmailMessage: email
$ ./bin/console messenger:consume
Symfony Maker Bundle
Symfony 4 recap
• Auto-configuration for any Composer package
• A Maker bundle to simplify creating files
• No boilerplate code, just business logic
• Controllers and commands as services
• From micro to monolith
• Meta-packages doing a lot for you out of the box
Productivity
boost!
Better DX
Why?
Featureful and the most downloaded
The most advanced API solution
https://api-platform.com/
The most advanced e-commerce solution
Many admin-gen solutions
https://github.com/EasyCorp/EasyAdminBundle
The foundation of the PHP ecosystem
$ composer require symfony/console
Truly independent components
(new ConsoleApplication('echo', '1.0.0'))
->register('echo')
->addArgument('foo', ConsoleInputInputArgument::OPTIONAL, 'The directory')
->addOption('bar', null, ConsoleInputInputOption::VALUE_REQUIRED)
->setCode(function(ConsoleInputInputInterface $input,
ConsoleOutputOutputInterface $output) {
// output arguments and options
})
->getApplication()
->setDefaultCommand('echo', true) // Single command application
->run();
• CssSelector
• Debug
• Dotenv
• Finder
• Mailer
• Mime
• sMessenger
• Polyfill : APCu, ctype, iconv, intl, mbstring, PHP, …
• Process
• VarDumper
• VarExporter
• Yaml
• …
Truly independent components
Predictable releases and support
https://symfony.com/releases
•Every month: a patch release
•Every 6 month: a minor release
•Every 2 years: a major release
•On the go: security releases
Predictable releases and support
Release
end of
support
+8 months +14 months +36 months +48 months
end of security
support
end of security
support
end of
support
Standard Releases
(3.3, 4.0)
LTS Releases
(2.8, 3.4)
Predictable releases and support
3.4
LTS
4.2
Stable
https://symfony.com/releases
Stability and predictability
• Strict semantic versioning
• Deprecation/BC policy
• Responsible security issue management
https://symfony.com/bc
https://symfony.com/security
The fastest framework around
x2
x3
x4
http://www.phpbenchmarks.com/
Scale from micro to monolith
13 files
15 dependencies
start with
…and grow as you see fit
via automation
Community oriented
• Code of conduct

https://symfony.com/conduct
• Enforced by the CARE team

https://symfony.com/care
• Respectful Review Comments

https://symfony.com/doc/current/contributing/community/review-comments.html
Diversity initiative

https://symfony.com/diversity
https://symfony.com/4
Thank you!

Fabien Potencier "Symfony 4 in action"

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
    $ symfony newdemo # Want to try Symfony 5.0 (dev version)? $ symfony new demo --version=dev-master
  • 7.
  • 8.
    symfony/skeleton "require": { "php": "^7.1.3", "ext-ctype":"*", "ext-iconv": "*", "symfony/console": "*", "symfony/dotenv": "*", "symfony/flex": "^1.1", "symfony/framework-bundle": "*", "symfony/yaml": "*" },
  • 9.
    $ symfony newdemo --version=dev-master --debug Demo
  • 10.
    $ symfony newdemo --version=dev-master --debug Demo
  • 11.
    $ symfony newdemo --version=dev-master --debug Demo "scripts": { "auto-scripts": { "cache:clear": "symfony-cmd", "assets:install %PUBLIC_DIR%": "symfony-cmd" }, "post-install-cmd": [ "@auto-scripts" ], "post-update-cmd": [ "@auto-scripts" ] },
  • 12.
    $ symfony newdemo --version=dev-master --debug Demo
  • 13.
    $ tree -Ivendor $ find . -type f | wc -l Symfony 4 is lightweight Only 16 files vs 31 SE 3300 total vs 8867 SE -65%
  • 14.
    New directory structure •Less depth, easier to navigate • Non-PHP files in their own directories (assets/, templates/) • Decoupled from Symfony (assets/, src/, templates/, public/)
  • 15.
  • 16.
  • 17.
    $ composer show| wc -l Demo Only 25 deps vs 38 + 50 = 88 SE
  • 18.
    Symfony 2+/3+ Monolog Bundle SwiftMailerBundle 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 BundleDoctrine 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 bundles42 components SwiftMailer
  • 19.
    Symfony 4+ Polyfill Mbstring FrameworkBundleCache Config Debug DependencyInjection Dotenv EventDispatcher Filesystem Finder HttpFoundation HttpKernel Routing Yaml 0 bridges 1 library 1 bundle13 components Flex
  • 20.
    $ symfony server:start-d $ symfony server:log Demo
  • 21.
  • 22.
  • 23.
    $ git init $git add . $ git commit -a -m"init" Demo
  • 24.
    $ composer reqmaker Demo
  • 25.
    Aliases • Shortcuts forcommon packages (log, behat, phpunit, …) • Optimized for Symfony Components (no need to use the symfony/ prefix, just workflow, dom-crawler, …) • Opinionated choices (admin, api, orm, mailer, test, …)
  • 26.
    Packs • Bundle severaldependencies into a consistent set (debug, profiler, api, test, …) $ composer req debug
  • 27.
    Discover Aliases andPacks https://flex.symfony.com/
  • 28.
    $ composer reqmaker $ git diff config/bundles.php Symfony Maker Bundle
  • 29.
    $ ./bin/console listmake Symfony Maker Bundle
  • 30.
  • 31.
    $ composer reqannot Symfony Maker Bundle
  • 32.
    $ ./bin/console make:controllerDefaultController Symfony Maker Bundle
  • 33.
    $ vim src/Controller/DefaultController.php SymfonyMaker Bundle src/ is about YOUR code
  • 34.
  • 35.
    $ composer reqtwig Adding Twig
  • 36.
  • 37.
    AddingaTwigExtension Where do Istore 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
  • 38.
    $ ./bin/console make:twig-extension Addinga Twig Extension Add your logic in the generated class… DONE!
  • 39.
    Full Automation worksfor… • Twig extensions • Event listeners • Doctrine repositories • Commands • Voters • Registration form system • …
  • 40.
    Beyond “Hello World” •Defining some models via Doctrine • Adding an API for my model • Managing data with an admin
  • 41.
    $ composer reqorm admin api Full stack really quick
  • 42.
    $ composer reqorm admin api Full stack really quick
  • 43.
    $ ./bin/console make:entityProduct --api-resource Full stack really quick
  • 44.
  • 45.
    $ vim .env DATABASE_URL="sqlite:///%kernel.project_dir%/var/ data.db" $./bin/console doctrine:database:create $ ./bin/console doctrine:schema:update --force Full stack really quick
  • 46.
    Itworks! One line configchange One annotation added
  • 48.
  • 49.
    I want tosend emails
 from my controller
  • 50.
    $ composer reqsymfony/mailer Symfony Maker Bundle use SymfonyComponentMailerMailerInterface; public function index(MailerInterface $mailer) { $mailer->send( (new Email()) ->from('fabien@symfony.com') ->to('fabien@symfony.com') ->subject('Some subject') ->text('Some text...') ); MAILER_DSN=smtp://localhost
  • 51.
    I want tosend rich emails
 from my controller
  • 52.
    Symfony Maker Bundle useSymfonyComponentMailerMailerInterface; public function index(MailerInterface $mailer) { $mailer->send( (new TemplatedEmail()) ->from('fabien@symfony.com') ->to('fabien@symfony.com') ->subject('Some subject') ->htmlTemplate('@emails/welcome.html.twig') ->context([ 'city' => 'Tunis' ]) ); MAILER_DSN=smtp://localhost
  • 53.
    I want tosend rich and responsive emails
 from my controller
  • 54.
    $ composer reqtwig/inky-extension Symfony Maker Bundle MAILER_DSN=smtp://localhost {% apply inky|inline_css(source("@zurb/stylesheets/main.css")) %} <container> <row class="header"> <columns> <spacer size="16"></spacer> <h4 class="text-center">Symfony Connect</h4> </columns> </row> <row> <columns> <spacer size="32"></spacer> <center><img width="100px" src="{{ email.image("@images/symfony.png") }}"></center> <spacer size="16"></spacer> <h1 class="text-center">Forgot Your Password?</h1> <spacer size="16"></spacer> <p class="text-center">It happens. Click the link below to reset it.</p> <button class="large expand" href="#">Reset Password</button> <hr/> <p><small><center><a href="#">unsubscribe here</a>.</small></center></p> </columns> </row> </container> {% endapply %}
  • 55.
    I want tosend rich and responsive emails
 from my controller
 via my provider's API
  • 56.
    $ composer reqsymfony/mailgun-mailer MAILER_DSN=http://key:domain@mailgun Symfony Maker Bundle AmazonSES GoogleGmail Mandrill Mailgun Postmark Sendgrid
  • 57.
    I want tosend rich and responsive emails
 from my controller
 via my provider's API
 asynchronously
  • 58.
    $ composer reqmessenger framework: messenger: transports: email: "doctrine://default" routing: SymfonyComponentMailerMessengerSendEmailMessage: email $ ./bin/console messenger:consume Symfony Maker Bundle
  • 59.
    I want tosend rich and responsive emails
 from my controller
 via my provider's API
 asynchronously with AMQP
  • 60.
    $ composer reqmessenger framework: messenger: transports: email: "amqp://guest:guest@localhost:5672/%2f/messages" routing: SymfonyComponentMailerMessengerSendEmailMessage: email $ ./bin/console messenger:consume Symfony Maker Bundle
  • 61.
    Symfony 4 recap •Auto-configuration for any Composer package • A Maker bundle to simplify creating files • No boilerplate code, just business logic • Controllers and commands as services • From micro to monolith • Meta-packages doing a lot for you out of the box Productivity boost! Better DX
  • 62.
  • 63.
    Featureful and themost downloaded
  • 64.
    The most advancedAPI solution https://api-platform.com/
  • 65.
    The most advancede-commerce solution
  • 66.
  • 67.
    The foundation ofthe PHP ecosystem
  • 68.
    $ composer requiresymfony/console Truly independent components (new ConsoleApplication('echo', '1.0.0')) ->register('echo') ->addArgument('foo', ConsoleInputInputArgument::OPTIONAL, 'The directory') ->addOption('bar', null, ConsoleInputInputOption::VALUE_REQUIRED) ->setCode(function(ConsoleInputInputInterface $input, ConsoleOutputOutputInterface $output) { // output arguments and options }) ->getApplication() ->setDefaultCommand('echo', true) // Single command application ->run();
  • 69.
    • CssSelector • Debug •Dotenv • Finder • Mailer • Mime • sMessenger • Polyfill : APCu, ctype, iconv, intl, mbstring, PHP, … • Process • VarDumper • VarExporter • Yaml • … Truly independent components
  • 70.
    Predictable releases andsupport https://symfony.com/releases •Every month: a patch release •Every 6 month: a minor release •Every 2 years: a major release •On the go: security releases
  • 71.
    Predictable releases andsupport Release end of support +8 months +14 months +36 months +48 months end of security support end of security support end of support Standard Releases (3.3, 4.0) LTS Releases (2.8, 3.4)
  • 72.
    Predictable releases andsupport 3.4 LTS 4.2 Stable https://symfony.com/releases
  • 73.
    Stability and predictability •Strict semantic versioning • Deprecation/BC policy • Responsible security issue management https://symfony.com/bc https://symfony.com/security
  • 74.
    The fastest frameworkaround x2 x3 x4 http://www.phpbenchmarks.com/
  • 75.
    Scale from microto monolith 13 files 15 dependencies start with …and grow as you see fit via automation
  • 76.
    Community oriented • Codeof conduct
 https://symfony.com/conduct • Enforced by the CARE team
 https://symfony.com/care • Respectful Review Comments
 https://symfony.com/doc/current/contributing/community/review-comments.html Diversity initiative
 https://symfony.com/diversity
  • 77.
  • 78.