Вы находитесь на странице: 1из 78

Fabien Potencier

@fabpot
Have you ever

used Symfony?
1.x? 2.x? 3.x? 4.x?
What is Symfony 4?
A new developer experience
On a rock solid foundation
From micro-style to monolith
4
in action…
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": "*"
},
Demo

$ symfony new demo --version=dev-master --debug


Demo

$ symfony new demo --version=dev-master --debug


Demo

$ symfony new demo --version=dev-master --debug

"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
Demo

$ symfony new demo --version=dev-master --debug


Symfony 4 is lightweight

$ tree -I vendor
Only 16 files
vs 31 SE

$ find . -type f | wc -l

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/)
Demo
https://github.com/symfony/recipes/

tree/master/

symfony/framework-bundle/4.2
Recipes repositories
https://github.com/symfony/recipes

Curated recipes by Symfony core team

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

Open to all contributions

370+ recipes
Demo

$ composer show | wc -l

Only 25 deps
vs 38 + 50 = 88 SE
Symfony 2+/3+
42 components Ldap Routing 4 bridges 11 bundles
Asset Dotenv OptionsResolver Security Doctrine Bridge Debug Bundle WebServer Bundle

BrowserKit EventDispatcher Polyfill APCu Serializer Monolog Bridge Distribution Bundle

Cache ExpressionLanguage Polyfill Intl ICU Stopwatch PHPUnit Bridge Framework Bundle

ClassLoader Filesystem Polyfill Mbstring Templating Twig Bridge FrameworkExtra Bundle

Config Finder Polyfill PHP 5.6 Translation 15 librairies Generator Bundle

Console Form Polyfill PHP 7.0 Validator Doctrine (11) Monolog Bundle

CssSelector HttpFoundation Polyfill Util VarDumper Monolog Security Bundle

Debug HttpKernel Process WebLink SecurityChecker SwiftMailer Bundle

DependencyInjection Inflector PropertyAccess Workflow ParamHandler Twig Bundle

DomCrawler Intl PropertyInfo Yaml SwiftMailer WebProfiler Bundle


Symfony 4+
13 components Routing 0 bridges 1 bundle
Dotenv

EventDispatcher

Cache Framework Bundle

Filesystem Polyfill Mbstring

Config Finder 1 library

HttpFoundation Flex

Debug HttpKernel

DependencyInjection

Yaml
Demo

$ symfony server:start -d
$ symfony server:log
Demo
Demo

$ ./bin/console

15 commands
vs 57 SE
Demo

$ git init
$ git add .
$ git commit -a -m"init"
Demo

$ composer req maker


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/
Symfony Maker Bundle

$ 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

src/ is about YOUR code


Symfony 4 helps you

grow your app

with ease
Adding Twig

$ composer req twig


Never define

your service again*
Adding a Twig Extension
hmm, ok

Which interface/class
do I need to implement/ Which tag do I need
extend? It’s too complex. What
to use? about doing it the dirty
way and do it in the
controller instead?

Which file do I How do I declare a


Where do I store
need to change to tag in YAML?
the Twig extension
register it?
class?
Adding a Twig Extension

$ ./bin/console make: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


Full stack really quick

$ 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
It works!

One line config change


One annotation added
Typical features
to the next level
I want to send emails

from my controller
Symfony Maker Bundle

$ composer req symfony/mailer


use Symfony\Component\Mailer\MailerInterface; MAILER_DSN=smtp://localhost

public function index(MailerInterface $mailer)


{
$mailer->send(
(new Email())
->from('fabien@symfony.com')
->to('fabien@symfony.com')
->subject('Some subject')
->text('Some text...')
);
I want to send rich emails

from my controller
Symfony Maker Bundle

use Symfony\Component\Mailer\MailerInterface; MAILER_DSN=smtp://localhost

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'
])
);
I want to send rich and responsive emails

from my controller
Symfony Maker Bundle

$ composer req twig/inky-extension


{% apply inky|inline_css(source("@zurb/stylesheets/main.css")) %}
<container>
<row class="header">
MAILER_DSN=smtp://localhost
<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
Symfony Maker Bundle

$ composer req symfony/mailgun-mailer Amazon SES


Google Gmail
Mandrill
MAILER_DSN=http://key:domain@mailgun
Mailgun
Postmark
Sendgrid
I want to send rich and responsive emails

from my controller

via my provider's API

asynchronously
Symfony Maker Bundle

$ composer req messenger

framework:
messenger:
transports:
email: "doctrine://default"

routing:
Symfony\Component\Mailer\Messenger\SendEmailMessage: email

$ ./bin/console messenger:consume
I want to send rich and responsive emails

from my controller

via my provider's API

asynchronously with AMQP
Symfony Maker Bundle

$ composer req messenger

framework:
messenger:
transports:
email: "amqp://guest:guest@localhost:5672/%2f/messages"

routing:
Symfony\Component\Mailer\Messenger\SendEmailMessage: email

$ ./bin/console messenger:consume
Symfony 4 recap
• Auto-configuration for any Composer package

• A Maker bundle to simplify creating files


Better DX
• No boilerplate code, just business logic

• Controllers and commands as services


Productivity
• From micro to monolith boost!

• Meta-packages doing a lot for you out of the box


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
Truly independent components

$ composer require symfony/console


(new Console\Application('echo', '1.0.0'))
->register('echo')
->addArgument('foo', Console\Input\InputArgument::OPTIONAL, 'The directory')
->addOption('bar', null, Console\Input\InputOption::VALUE_REQUIRED)
->setCode(function(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output) {
// output arguments and options
})
->getApplication()
->setDefaultCommand('echo', true) // Single command application
->run();
Truly independent components
• CssSelector
• Debug
• Dotenv
• Finder
• Mailer
• Mime
• sMessenger
• Polyfill : APCu, ctype, iconv, intl, mbstring, PHP, …
• Process
• VarDumper
• VarExporter
• Yaml
• …
Predictable releases and support
•Every month: a patch release
•Every 6 month: a minor release
•Every 2 years: a major release
•On the go: security releases

https://symfony.com/releases
Predictable releases and support
Release +8 months +14 months +36 months +48 months

end of end of security


support support

Standard Releases
(3.3, 4.0)
end of end of security
support support

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
start with
13 files
… and grow as you see fit
via automation
15 dependencies
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!

Вам также может понравиться