Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony 4 / Flex

Symfony 4 / Flex

Keynote about Symfony 4 / Flex at SymfonyCon Cluj 2017

Fabien Potencier

November 17, 2017
Tweet

More Decks by Fabien Potencier

Other Decks in Programming

Transcript

  1. Fabien Potencier
    @fabpot

    View full-size slide

  2. What is Symfony 4?
    = Symfony 3.4 LTS

    - deprecated features

    - long term support

    - PHP 5 support

    + new dev workflow via Flex

    View full-size slide

  3. Flex
    Composition over Inheritance

    View full-size slide

  4. Flex in 1 sentence
    Flex helps developers manage the life-cycle of
    project dependencies by automating boring
    tasks,

    For projects of any size, from micro to monolith,

    For any kind of applications, API or Web.

    View full-size slide

  5. Flex in 10 seconds
    Projects do not depend on symfony/symfony

    No third-party dependencies/bundles

    Add dependencies when you need them

    Nothing to remove, the bare minimum

    View full-size slide

  6. Flex behind the scenes
    Composer plugin

    Uses “recipes” to install/uninstall any Composer
    package (enables bundles, auto-configures
    packages, …)

    View full-size slide

  7. Flex
    in action…

    View full-size slide

  8. $ composer create-project symfony/skeleton demo
    # Before Symfony 4 stable
    $ composer create-project -s beta symfony/
    skeleton demo

    View full-size slide

  9. symfony/skeleton
    "require": {
    "php": "^7.0.8",
    "symfony/console": "^4.0",
    "symfony/flex": "^1.0",
    "symfony/framework-bundle": "^4.0",
    "symfony/lts": "^4@dev",
    "symfony/yaml": "^4.0"
    },
    "require-dev": {
    "symfony/dotenv": "^4.0"
    },

    View full-size slide

  10. symfony/lts
    Enforces Long Term Supported versions of the
    Symfony Components

    View full-size slide

  11. $ composer create-project symfony/skeleton demo
    Demo

    View full-size slide

  12. $ composer create-project symfony/skeleton demo
    Demo

    View full-size slide

  13. $ composer create-project symfony/skeleton demo
    Demo

    View full-size slide

  14. $ composer create-project symfony/skeleton demo
    Demo

    View full-size slide

  15. $ tree -I vendor
    $ find . -type f | wc -l
    Symfony 4 is lightweight
    Only 13 files
    vs 31 SE
    2503 total
    vs 8867 SE
    -70%

    View full-size slide

  16. New directory structure
    • Less depth, easier to navigate
    • Non-PHP files in their own directories (assets/,
    templates/)
    • Decoupled from Symfony (assets/, src/,
    templates/, public/)

    View full-size slide

  17. https://github.com/symfony/recipes/
    symfony/framework-bundle/3.3
    Demo

    View full-size slide

  18. symfony.lock

    View full-size slide

  19. Recipes repositories
    https://github.com/symfony/recipes

    Curated recipes by Symfony core team

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

    Open to all contributions
    150+ recipes

    View full-size slide

  20. Symfony Bot
    Validates contributions

    View full-size slide

  21. Symfony Bot
    Let’s you test a recipe

    before merging

    View full-size slide

  22. Symfony Bot
    Auto-merge pull requests

    View full-size slide

  23. $ composer show | wc -l
    Demo
    Only 21 deps
    vs 38 + 50 = 88 SE

    View full-size slide

  24. Symfony Standard Edition
    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

    View full-size slide

  25. Symfony Flex / Symfony 4.0
    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

    View full-size slide

  26. $ ./bin/console
    Demo
    13 commands
    vs 57 SE

    View full-size slide

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

    View full-size slide

  28. $ composer req maker:dev-master
    Demo

    View full-size slide

  29. 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, …)

    View full-size slide

  30. Packs
    • Bundle several dependencies into a
    consistent set (debug, profiler, api, …)
    $ composer req debug

    View full-size slide

  31. Discover Aliases and Packs
    https://symfony.sh/

    View full-size slide

  32. Flex private repositories

    View full-size slide

  33. $ composer config extra.symfony.id
    Register
    Flex private repositories

    View full-size slide

  34. $ composer req maker:dev-master
    $ git diff config/bundles.php
    Symfony Maker Bundle

    View full-size slide

  35. $ ./bin/console list make
    Symfony Maker Bundle

    View full-size slide

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

    View full-size slide

  37. $ composer req annot
    Symfony Maker Bundle

    View full-size slide

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

    View full-size slide

  39. $ vim config/routes.yaml
    Symfony Maker Bundle

    View full-size slide

  40. $ vim src/Controller/DefaultController.php
    Symfony Maker Bundle
    src/ is bundle-less

    View full-size slide

  41. Application code is no
    longer divided into bundles.

    View full-size slide

  42. Symfony 4 helps you

    grow your app

    with ease

    View full-size slide

  43. $ composer req twig
    Adding Twig

    View full-size slide

  44. Never define

    your service again*

    View full-size slide

  45. 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

    View full-size slide

  46. $ ./bin/console make:twig-extension
    Adding a Twig Extension
    Add your logic in the
    generated class…
    DONE!

    View full-size slide

  47. Full Automation works for…
    • Twig extensions
    • Event listeners
    • Doctrine repositories
    • Commands
    • Voters
    • …

    View full-size slide

  48. Beyond “Hello World”
    • Defining some models via Doctrine
    • Adding an API for my model
    • Managing data with an admin

    View full-size slide

  49. $ composer req orm admin api
    Full stack really quick

    View full-size slide

  50. $ ./bin/console make:entity Product
    $ vim config/packages/easy_admin.yaml
    Full stack really quick

    View full-size slide

  51. $ 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

    View full-size slide

  52. DSNs
    parameters:
    database_host: 127.0.0.1
    database_port: null
    database_name: symfony
    database_user: root
    database_password: null
    Symfony 2/3
    Symfony 4
    DATABASE_URL = "mysql://[email protected]:3306/symfony"
    MAILER_URL
    REDIS_URL

    View full-size slide

  53. It works!
    One line config change
    One annotation added

    View full-size slide

  54. Symfony 4 with Flex recap
    • Auto-configuration for any Composer package
    • A new Maker bundle to simplify creating files
    • Support for Flex private repositories
    • No more boilerplate code, just business logic
    • Controllers and commands are services now
    • From micro to monolith
    • Meta-packages doing a lot for you out of the box
    Productivity
    boost!
    Better DX

    View full-size slide

  55. More with Symfony 4
    • Dependency injection without thinking about it
    • API Platform, the most advanced API system
    • Admin, simple and powerful
    • Symfony Encore, makes working with Webpack
    enjoyable
    Talk at
    Cluj!
    Talk at
    Cluj!
    Talk at
    Cluj!

    View full-size slide

  56. More with Symfony 4
    HTTP2
    push
    support Inject secrets
    as parameters
    (Docker/K8s)
    Built-in PSR-3
    logger
    Env vars
    where it makes
    sense
    DI simplified,
    classes as IDs
    PSR-11,
    PSR-6, PSR-16
    out of the box
    Private
    services by
    default

    View full-size slide

  57. Env/Debug mode
    // web/app_dev.php
    $kernel = new AppKernel('dev', true);
    $request = Request::createFromGlobals();
    // ...
    // web/app.php
    $kernel = new AppKernel('prod', false);
    $request = Request::createFromGlobals();
    // ...
    Symfony 2/3 Symfony 4
    # .env
    APP_ENV = dev
    APP_DEBUG = 1
    Enables the merge of

    app.php and app_dev.php
    to a single index.php

    View full-size slide

  58. … which simplifies running commands
    # Symfony 2/3
    $ ./bin/console foo:bar --env=prod —no-debug
    $ SYMFONY_ENV=prod SYMFONY_DEBUG=0 ./bin/console
    foo:bar
    # Symfony 4
    $ ./bin/console foo:bar

    View full-size slide

  59. Deprecating

    the obsolete

    View full-size slide

  60. Long READMEs

    are a thing of the past
    WITHOUT
    Flex
    WITH
    Flex

    View full-size slide

  61. Symfony Standard Edition
    • Not available for Symfony 4
    • But still maintained for Symfony 2.7 -> 3.4
    • EOL November 2020
    Use Flex

    View full-size slide

  62. Symfony Installer
    • Not available for Symfony 4
    • But still maintained for Symfony 2.7 -> 3.4
    • EOL November 2020 Use plain
    Composer
    and Flex

    View full-size slide

  63. symfony/symfony as a dep
    • Won’t be enforced
    • But strongly not recommended
    • Won’t be removed as still the best way to
    manage the project
    Use explicit
    dependencies

    View full-size slide

  64. Silex
    • New Symfony features not supported
    • EOL June 2018
    Use Flex

    View full-size slide

  65. symfony 1
    • Last major release 7 years ago
    • End of life 5 years ago
    • End of infrastructure: December 2017
    Use Symfony
    2/3/4

    View full-size slide

  66. No longer recommended
    • Symfony Standard Edition (EOL nov 2020)
    • Symfony Installer (EOL nov 2020)
    • symfony/symfony as a Composer dep (EOL nov 2020)
    • Silex (EOL june 2018)
    • symfony 1 (EOL dec 2017)

    View full-size slide

  67. https://symfony.com/4

    View full-size slide

  68. What’s next?

    View full-size slide

  69. 5 initiatives to grow
    Led by the
    community
    Supported by the
    Core Team
    And SensioLabs

    View full-size slide

  70. 5 new initiatives
    … to grow the community

    View full-size slide

  71. Upgrade to 4
    … all Symfony bundles and the ecosystem

    View full-size slide

  72. Recipes Team
    … to review, approve, and merge contributions

    View full-size slide

  73. Security Team
    … to manage the whole process

    View full-size slide

  74. Integrations
    … to provide higher-level integrations

    View full-size slide

  75. Current “integrations”, small and big
    • Monolog
    • Gmail support in semantic configuration
    • Assetic / Encore
    • Bootstrap 3 / 4

    View full-size slide

  76. Some “random” ideas
    • Search engine: Algolia, ElasticSearch
    • Multi-factor authentication (Google Authenticator) / SAML
    • Structured logs
    • VueJS
    • Queues / Workers
    • Transactional email providers (Mailgun, Postmark, …)
    • Payment gateways (Stripe)
    • …

    View full-size slide

  77. Diversity
    …scholarship, mentorship, …

    View full-size slide