Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

A dive into Symfony 4

595 views

Published on

An overview of the features of this framework: new directory structure, bundleless apps with flex and much more

Published in: Technology
  • Login to see the comments

A dive into Symfony 4

  1. 1. A dive into Symfony 4
  2. 2. A long time ago... Symfony 2 was born
  3. 3. Key Concepts Components Bundles Distributions
  4. 4. Time passed by...
  5. 5. How did it go?
  6. 6. Bene... ma non benissimo :-(
  7. 7. Bene... ma non benissimo :-(
  8. 8. Distributions Initial idea: one distribution per app type • Standard Distribution • Rest Distribution • Cms Distribution • ...
  9. 9. Distributions In Reality: distributions never took off, everybody uses Standard Distribution and removes stuff manually
  10. 10. Bundles Initial Idea: organise reusable code in bundles
  11. 11. Bundles Have you ever seen this organisation? ShopBundle CmsBundle AdminBundle ...
  12. 12. Bundles Have you ever seen this organisation? ShopBundle CmsBundle AdminBundle Common|General| ... | Bundle
  13. 13. Bundles Vendor code is reusable Your App code is not
  14. 14. Bundles Installing/Removing a Bundle is mostly a manual operation # composer require/remove <bundle> # add/remove to AppKernel.php # add/remove configurations
  15. 15. DX initiative Symfony has a steep learning curve compared to other frameworks The Developer eXperience initiative aims to create a better onboarding and framework usage experience
  16. 16. DX initiative Symfony has a steep learning curve compared to other frameworks The Developer eXperience initiative aims to create a better user experience
  17. 17. Symfony 4 was born...
  18. 18. New Directory Structure
  19. 19. New Directory Structure The idea behind that is to have a more intuitive structure
  20. 20. New Directory Structure bin
 config
 public 
 src
 var
 vendor
  21. 21. New Directory Structure bin
 config
 public 
 src
 var
 vendor index.php ... favicon.ico robots.txt bundles
  22. 22. New Directory Structure bin
 config
 public 
 src
 var
 vendor cache/ log/ session/
  23. 23. New Directory Structure bin
 config
 public 
 src
 var
 vendor Kernel.php Entity Repository Command Controller ...
  24. 24. No Bundles!
  25. 25. New Directory Structure bin
 config
 public 
 src
 var
 vendor bundles.php
 routes.yaml
 services.yaml
 doctrine.yaml
 security.yaml
 ...
 packages/
 dev/ routes.yaml
 test/ routes.yaml
 prod/ routes.yaml
  26. 26. return [
 SymfonyBundleFrameworkBundleFrameworkBundle::class => ['all' => true],
 SymfonyBundleWebServerBundleWebServerBundle::class => ['dev' => true],
 SymfonyBundleMakerBundleMakerBundle::class => ['dev' => true],
 SymfonyBundleDebugBundleDebugBundle::class => ['dev' => true, 'test' => true],
 SymfonyBundleSecurityBundleSecurityBundle::class => ['all' => true],
 ];
  27. 27. New Directory Structure assets
 bin
 data
 config
 public 
 src
 templates
 tests
 translations
 var
 vendor
  28. 28. Where is parameter.yaml?
  29. 29. Environment Variables
  30. 30. Environment Variables Symfony already has them eg. SYMFONY__ENV
  31. 31. Environment Variables Now resolved at runtime! You can change them without touching the app https://www.12factor.net/config
  32. 32. Environment Variables doctrine:
 dbal:
 driver: 'pdo_sqlite'
 server_version: '3.15'
 charset: utf8mb4
 url: ‘%env(resolve:DATABASE_URL)%' 
 https://symfony.com/blog/new-in-symfony-3-4-advanced-environment-variables
  33. 33. .env ###> symfony/framework-bundle ### APP_ENV=dev APP_SECRET=2a0f335581bd72b6077840e29d73ba36 TRUSTED_PROXIES=127.0.0.1,127.0.0.2 TRUSTED_HOSTS=localhost,example.com,127.0.0.1 ###< symfony/framework-bundle ###
  34. 34. index.php if (!isset($_SERVER['APP_ENV'])) {
 if (!class_exists(Dotenv::class)) {
 throw new RuntimeException('APP_ENV environment variable is not defined.’);
 }
 
 (new Dotenv())->load(__DIR__.'/../.env');
 } $env = $_SERVER['APP_ENV'] ?? 'dev';
 $debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));
  35. 35. Symfony Flex
  36. 36. Flex A new way to create and evolve a Symfony application Composition over inheritance Start small and add what you need
  37. 37. Flex Integrates into composer workflow Automates bundles installation and configuration
  38. 38. Flex
  39. 39. Flex
  40. 40. Flex { "bundles": { "SymfonyBundleFrameworkBundleFrameworkBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/", "public/": "%PUBLIC_DIR%/", "src/": "%SRC_DIR%/" }, "composer-scripts": { "make cache-warmup": "script", "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/" ] } https://medium.com/@fabpot/symfony-4-automate-your-workflow-fbbf609b5a1d
  41. 41. symfony.sh
  42. 42. recipes https://github.com/symfony/recipes https://github.com/symfony/recipes-contrib
  43. 43. alias orm, twig, security, form, validation, ...
  44. 44. So long Standard Edition...
  45. 45. composer require symfony/website-skeleton
  46. 46. composer require symfony/skeleton
  47. 47. So long Silex... https://symfony.com/blog/the-end-of-silex
  48. 48. Other Bits...
  49. 49. From Sf 3.* to Sf 4 Symfony 3.4 is Symfony 4 with and additional compat layer Migration path: upgrade to 3.4, remove deprecations, update to 4 https://symfony.com/doc/current/setup/flex.html#upgrade-to-flex
  50. 50. Autowiring Wait 5 minutes... :-P
  51. 51. composer require make MakerBundle
  52. 52. make:auth make:command make:controller make:crud make:entity make:fixtures make:form make:functional-test make:migration make:serializer:encoder make:subscriber make:twig-extension make:unit-test make:user make:validator make:voter
  53. 53. Fastest PHP Router https://symfony.com/blog/new-in-symfony-4-1-fastest-php-router
  54. 54. VarDumper Server https://symfony.com/blog/new-in-symfony-4-1-vardumper-server
  55. 55. Messenger Component https://symfony.com/blog/new-in-symfony-4-1-messenger-component
  56. 56. Panther https://symfony.com/blog/introducing-symfony-panther-a-browser- testing-and-web-scrapping-library-for-php
  57. 57. Moar Improvements https://symfony.com/blog/new-in-symfony-4-1-exception-improvements
 https://symfony.com/blog/new-in-symfony-4-1-session-improvements
 https://symfony.com/blog/new-in-symfony-4-1-self-updating-debug-toolbar
 https://symfony.com/blog/new-in-symfony-4-1-console-improvements
 https://symfony.com/blog/new-in-symfony-4-1-form-field-help
 https://symfony.com/blog/new-in-symfony-4-1-faster-serializer
 https://symfony.com/blog/new-in-symfony-4-1-misc-improvements-part-1
 https://symfony.com/blog/new-in-symfony-4-1-misc-improvements-part-2
 https://symfony.com/blog/new-in-symfony-4-1-misc-improvements-part-3
 https://symfony.com/blog/new-in-symfony-4-1-misc-improvements-part-4
 https://symfony.com/blog/new-in-symfony-4-2-samesite-cookie-configuration
 https://symfony.com/blog/new-in-symfony-4-2-varexporter-component
 https://symfony.com/blog/new-in-symfony-4-2-intlmessageformatter
 https://symfony.com/blog/new-in-symfony-4-2-auto-secure-cookies
  58. 58. Thank you! Michele Orselli _orso_ micheleorselli / ideatosrl mo@ideato.it https://joind.in/talk/2a90f

×