Symfony Flex in Action

Symfony Flex in Action

This talk was hold on October 27th with Christian Flothmann (@xabbuh) at SymfonyLive in Berlin.

Symfony Flex is a revolution in the world of Symfony and changes the way of building applications. A developer needs to focus more on dependencies, but can easily increase productivity and lower the footprint of an application. We accompanied Symfony on the way to the new Flex era and will give you concrete examples how application development now looks like and explain the key concepts.

0bee6a2886272e60be8888ae48baf42d?s=128

Christopher Hertel

October 27, 2017
Tweet

Transcript

  1. SensioLabs Flex in Action

  2. SensioLabs Who are we?

  3. Christopher Hertel Software Developer at SensioLabs Symfony User Group Berlin

    @el_stoffel Christian Flothmann Software Developer at SensioLabs Symfony Docs & Core Team @xabbuh
  4. SensioLabs Diving into Flex

  5. ©Adobe Systems Software

  6. ©Apache Software Foundation

  7. ©Bosch Media Service

  8. SensioLabs Symfony Flex

  9. Why Flex?

  10. applications based on Standard Edition

  11. symfony/asset symfony/browser-kit symfony/cache symfony/config symfony/console symfony/css-selector symfony/dependency-injection symfony/debug symfony/debug-bundle symfony/doctrine-bridge

    symfony/dom-crawler depends on symfony/symfony
  12. massive dependency graph

  13. hard to customize

  14. redundant steps to install bundles

  15. Flex to the rescue!

  16. start clean

  17. composition over inheritance

  18. know your dependencies

  19. automation

  20. The Schedule

  21. Symfony Flex can already be used

  22. We are here

  23. Symfony 3.4 end of November

  24. Symfony 3.4 = Symfony 3.3 + new features + new

    deprecations
  25. Symfony 4 at the same time

  26. Symfony 4.0 = Symfony 3.4 - deprecated features

  27. Symfony 4 != Flex

  28. Flex usable with Symfony 3.3

  29. Symfony 4 usable without Flex

  30. PHP Requirements Flex 7.0.8 Symfony 4 7.1.3

  31. SensioLabs Hands on

  32. Installation

  33. Symfony Installer

  34. Flex is a Composer Plugin

  35. Hooks into Composer‘s lifecycle

  36. $ composer create-project \ symfony/skeleton my-app New applications $ composer

    create-project \ symfony/skeleton my-app
  37. Symfony 4 Beta $ composer create-project \ symfony/skeleton:^4.0@beta my-app

  38. Standard Edition

  39. Anatomy

  40. Initial size decreases

  41. $ symfony new my-app $ du –sh my-app 53M my-app

    $ cloc my-app 652.336 LOC Standard Edition
  42. $ composer create symfony/skeleton my-app $ du –sh my-app 14M

    my-app $ cloc my-app 135.726 LOC Flex
  43. Directory Structure

  44. . |─ app/ │ |─ config/ | | |─ config.yml

    | | └─ parameters.yml | |─ Resources/ | | └─ views/ | └─ AppKernel.php |─ bin/ | └─ console |─ src/ │ └─ AppBundle/ │ └─ Controller/ |─ var/ |─ vendor/ |─ web/ | |─ app.php | └─ app_dev.php └─ composer.json/lock Symfony Standard Application Config Infrastructure Config Templates Kernel Console Application Source /var DocRoot FrontController Composer
  45. Symfony Standard Flex . |─ bin/ | └─ console |─

    config/ │ |─ packages/ | |─ bundles.php |─ src/ │ |─ Controller/ | └─ Kernel.php |─ templates/ |─ public/ | └─ index.php |─ var/ |─ vendor/ |─ .env └─ composer.json/lock . |─ app/ │ |─ config/ | | |─ config.yml | | └─ parameters.yml | |─ Resources/ | | └─ views/ | └─ AppKernel.php |─ bin/ | └─ console |─ src/ │ └─ AppBundle/ │ └─ Controller/ |─ var/ |─ vendor/ |─ web/ | |─ app.php | └─ app_dev.php └─ composer.json/lock
  46. Symfony Standard Flex . |─ bin/ | └─ console |─

    config/ │ |─ bundles.php | |─ packages/ |─ src/ │ |─ Controller/ | └─ Kernel.php |─ templates/ |─ translations/ |─ public/ | └─ index.php |─ var/ |─ vendor/ |─ .env └─ composer.json/lock . |─ app/ │ |─ config/ | | |─ config.yml | | └─ parameters.yml | |─ Resources/ | | └─ views/ | └─ AppKernel.php |─ bin/ | └─ console |─ src/ │ └─ AppBundle/ │ └─ Controller/ |─ var/ |─ vendor/ |─ web/ | |─ app.php | └─ app_dev.php └─ composer.json/lock |─ translations/ Translations
  47. Symfony Standard Flex . |─ assets/ |─ bin/ | └─

    console |─ config/ │ |─ bundles.php | |─ packages/ |─ src/ │ |─ Controller/ | └─ Kernel.php |─ templates/ |─ public/ │ |─ build/ | └─ index.php |─ var/ |─ vendor/ |─ .env └─ composer.json/lock . |─ app/ │ |─ config/ | | |─ config.yml | | └─ parameters.yml | |─ Resources/ | | └─ views/ | └─ AppKernel.php |─ bin/ | └─ console |─ src/ │ └─ AppBundle/ │ └─ Controller/ |─ var/ |─ vendor/ |─ web/ | |─ app.php | └─ app_dev.php └─ composer.json/lock |─ assets/ │ |─ build/ Webpack Encore
  48. Config Directory

  49. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-…
  50. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Bundle Configuration
  51. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Environment Specific Configuration
  52. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Infrastructure Specific Configuration
  53. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Routing
  54. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Environment Specific Routing
  55. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Security Configuration
  56. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… Container Configuration
  57. Symfony Standard Flex . |─ config/ │ |─ packages/ |

    | |─ dev/ | | |─ prod/ | | |─ test/ | | |─ doctrine.yaml | | |─ framework.yaml | | └─ security.yaml │ |─ routes/ | | └─ dev/ | | └─ twig.yaml │ |─ bundles.php │ |─ routes.yaml | └─ services.yaml |─ .env |─ .env.dist |─ ... . |-app/ │ |-config/ | | |-config.yml | | |-config_dev.yml | | |-config_prod.yml | | |-config_test.yml | | |-parameters.yml | | |-parameters.yml.dist | | |-routing.yml | | |-routing_dev.yml | | |-security.yml | | └-services.yml |-… bundles.php
  58. bundles.php <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], ];

    <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], ]; <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], ]; <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class =>['dev'=>true, 'test'=>true], ]; <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class =>['dev'=>true, 'test'=>true], Symfony\Bundle\WebserverBundle\WebserverBundle::class => ['dev' => true], ];
  59. SensioLabs Insides

  60. Recipes

  61. actions performed on package installation

  62. reviewed and maintained by core team

  63. automatically executed

  64. available only for selected packages

  65. { "bundles": { "Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/",

    "public/": "%PUBLIC_DIR%/", "src/": "%SRC_DIR%/" }, "composer-scripts": { "cache:clear": "symfony-cmd", "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd" }, "env": { "APP_ENV": "dev", "APP_DEBUG": "1", "APP_SECRET": "%generate(secret)%" }, "gitignore": [ ".env", "/public/bundles/", "/var/", "/vendor/" ] } Example: symfony/framework-bundle
  66. None
  67. What about other packages?

  68. Contrib Recipes

  69. maintained by the community

  70. not applied automatically

  71. { "extra": { "symfony": { "id": "01BX217DNRHSWETJFT83M3XDE9", "allow-contrib": } }

    } false
  72. Interactive activation

  73. SensioLabs Example Apps

  74. Mailing Service

  75. Feature Requirements • JSON Endpoints per mailing • Sending HTML

    mails • Mail spooling
  76. 1. Create project $ composer create-project \ symfony/skeleton:^4.0@beta \ flex-mailer

    $ composer require \ logger annotations mailer twig
  77. 2. Configuration # config/packages/swiftmailer.yaml swiftmailer: url: '%env(MAILER_URL)%' spool: path: '%kernel.project_dir%/var/mailing-spool'

    # config/routes.yaml controllers: resource: ../src/Controller/ type: annotation defaults: { _format: json }
  78. 3. Mailer (Domain)

  79. 4. Controller (Framework)

  80. 5. Testing

  81. Product Import

  82. Feature Requirements • Command line tool • Parse CSV file

    • Persist products in database
  83. 1. Create project $ composer create-project \ symfony/skeleton:^4.0@beta \ flex-importer

    $ composer require logger orm
  84. 3. Entity

  85. 4. Importer

  86. 5. Command

  87. 6. Testing

  88. SensioLabs Recap

  89. more automated development workflow

  90. better dependency control

  91. smaller footprint

  92. increased productivity while shaping your apps

  93. Thank you!

  94. See you @ Hackathon 19.00 pm – 11th floor

  95. Feedback? joind.in/talk/ce4b4

  96. None
  97. Questions?

  98. None