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

Getting Started with Symfony 4 and Flex

Getting Started with Symfony 4 and Flex

With the release of Symfony4, both the architecture and the developer workflow got a major overhaul, mostly by the introduction of Flex as a way to bootstrap your application. The new changes focus on enabling easier cloud deployments & less manual configuration, while supporting both lean microservice setups as well as monolithic applications. I will guide you through these changes to quickly get started with your new projects.

Denis Brumann

June 07, 2018
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex Symfony 3.4 Symfony 3.3
 + Additional Features
 + Deprecations LTS Release
 3 years support Symfony 4.0 Symfony 3.3
 + Additional Features
 - Deprecations Standard Release
 8 months support
  2. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex Symfony 4 != Flex You can use Symfony 4 without Flex • Upgrade PHP (>=7.1.3) • Remove deprecations • Upgrade symfony/symfony to ^4.0
  3. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex Symfony Standard Edition Symfony 2/3 applications were based
 on the Symfony Standard Edition (SE). Symfony SE shipped with all components
 and various bundles. Unused functionality is dormant or
 must be removed.
  4. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex Symfony Flex • replaces Symfony Installer (symfony new) • Composer plugin • Autoconfigures bundles • Executes predefined recipes • Removes changes from recipe on uninstall Functionality is downloaded when needed
  5. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex composer create-project \
 symfony/framework-standard-edition:^3.3 \
 my-app
  6. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex composer create-project \
 symfony/skeleton my-app
  7. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex composer create-project \
 symfony/website-skeleton my-app
  8. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── LICENSE ├── README.md ├── app ├── bin ├── composer.json ├── composer.lock ├── phpunit.xml.dist ├── src ├── tests ├── var ├── vendor └── web
  9. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── app ├── bin ├── composer.json ├── composer.lock ├── src ├── var ├── vendor └── web . ├── bin ├── composer.json ├── composer.lock ├── config ├── public ├── src ├── symfony.lock ├── var └── vendor
  10. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── app ├── bin ├── composer.json ├── composer.lock ├── src ├── var ├── vendor └── web . ├── bin ├── composer.json ├── composer.lock ├── config ├── public ├── src ├── symfony.lock ├── var └── vendor
  11. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex dbr:skeleton/ (master*) $ bin/console list Symfony 4.0.9 (kernel: src, env: dev, debug: true) Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -e, --env=ENV The Environment name. [default: "dev"] --no-debug Switches off debug mode. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: about Displays information about the current project help Displays help for a command list Lists commands assets assets:install Installs bundles web assets under a public directory cache cache:clear Clears the cache cache:pool:clear Clears cache pools cache:pool:prune Prunes cache pools cache:warmup Warms up an empty cache config config:dump-reference Dumps the default configuration for an extension debug debug:autowiring Lists classes/interfaces you can use for autowiring debug:config Dumps the current configuration for an extension debug:container Displays current services for an application debug:event-dispatcher Displays configured listeners for an application debug:router Displays current routes for an application lint lint:yaml Lints a file and outputs encountered errors router router:match Helps debug routes by simulating a path info match
  12. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── app ├── bin ├── composer.json ├── composer.lock ├── src ├── var ├── vendor └── web . ├── bin ├── composer.json ├── composer.lock ├── config ├── public ├── src ├── symfony.lock ├── var └── vendor
  13. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex app ├── AppCache.php ├── AppKernel.php ├── Resources │ └── views └── 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 config ├── bundles.php ├── packages │ ├── dev │ │ └── routing.yaml │ ├── framework.yaml │ ├── routing.yaml │ └── test │ └── framework.yaml ├── routes.yaml └── services.yaml
  14. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── app ├── bin ├── composer.json ├── composer.lock ├── src ├── var ├── vendor └── web . ├── bin ├── composer.json ├── composer.lock ├── config ├── public ├── src ├── symfony.lock ├── var └── vendor
  15. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex app_dev.php app.php index.php APP_ENV: dev | prod APP_DEBUG: true | false .env
  16. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── app ├── bin ├── composer.json ├── composer.lock ├── src ├── var ├── vendor └── web . ├── bin ├── composer.json ├── composer.lock ├── config ├── public ├── src ├── symfony.lock ├── var └── vendor
  17. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── SymfonyRequirements.php ├── bootstrap.php.cache ├── cache │ └── dev ├── logs │ └── dev.log └── sessions var ├── cache │ └── dev └── log
  18. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . ├── app ├── bin ├── composer.json ├── composer.lock ├── src ├── var ├── vendor └── web . ├── bin ├── composer.json ├── composer.lock ├── config ├── public ├── src ├── symfony.lock ├── var └── vendor
  19. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex . └── AppBundle ├── AppBundle.php └── Controller └── DefaultController.php . ├── Controller └── Kernel.php formerly
 app/AppKernel (without bundle registration)
  20. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex What is a bundle? Bundles are intended to be reusable components for sharing features between applications. Bundles are Symfony's version of a plugin-system.
  21. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex Migrating a bundled application Move code to App\ and use namespaces for ordering functionality, e.g.
 App\Controller\Backend\IndexController. Install bundles using composer.
  22. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex How to add functionality to a Flex project? Unlike Standard Edition, which came with ready-to-use bundles and default config,
 new components/bundles are added on demand. Flex will automatically enable a bundle in all
 appropriate environments and add necessary
 configuration through recipes & packs.
  23. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex What is a recipe? • Description of things to apply when a package is installed or to be removed on uninstall • maintained by Symfony Core team • stored in Github-repository: symfony/recipes • automatically applied via flex-plugin
  24. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex Packs groups of several packages solving a common problem Recipes registers a bundle with optional configuration, environment variables
 and files
  25. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex What are a contrib-recipes? • maintained by the community • no guaranteed quality standard • open to recipes with certain OS licenses • recipes are not enabled by default
  26. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. public: false # Allows optimizing the container by removing unused services; this also means # fetching services directly from the container via $container->get() won't work. # The best practice is to be explicit about your dependencies anyway. # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/*' exclude: '../src/{Entity,Migrations,Tests,Kernel.php}' # controllers are imported separately to make sure services can be injected # as action arguments even if you don't extend any base controller class App\Controller\: resource: '../src/Controller' tags: ['controller.service_arguments']
  27. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex _defaults: autowire: true autoconfigure: true public: false
  28. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex App\: resource: '../src/*' exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
  29. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex App\Controller\: resource: '../src/Controller' tags: ['controller.service_arguments']
  30. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex App\Meetup\Mailer: arguments: $adminMail: '%env(ADMIN_MAIL)%'
  31. Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 &

    Flex _defaults: bind: $adminMail: '%env(ADMIN_MAIL)%'