Slide 1

Slide 1 text

Getting started with
 Symfony 4 & Flex Denis Brumann [email protected] @dbrumann

Slide 2

Slide 2 text

Denis Brumann Software Developer
 Berlin, Germany [email protected] @dbrumann

Slide 3

Slide 3 text

Symfony Versions

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 & Flex Maintained Versions 2.8 3.4 4.0 4.1

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Bootstrapping a Symfony application

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 & Flex symfony new my-app 3.3

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

New
 Directory Structure

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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)

Slide 30

Slide 30 text

Bundle-less
 applications

Slide 31

Slide 31 text

Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 & Flex Your bundles will still work!

Slide 32

Slide 32 text

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.

Slide 33

Slide 33 text

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.

Slide 34

Slide 34 text

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.

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Dependency Injection Improvements

Slide 44

Slide 44 text

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']

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

Denis Brumann [email protected] @dbrumann Getting Started with Symfony 4 & Flex _defaults: bind: $adminMail: '%env(ADMIN_MAIL)%'

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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