Slide 1

Slide 1 text

Symfony 4 & Symfony Flex Core ideas, features and improvements Victoria Quirante

Slide 2

Slide 2 text

I work at Limenius We build tailor-made projects with Symfony and React We have been working with Symfony since 2008 SF4 means a significant evolution Victoria Quirante @vicqr [email protected]

Slide 3

Slide 3 text

SYMFONY 4 MOTIVATION What are the driving forces behind this new version https://www.flickr.com/photos/gsfc/14411386334

Slide 4

Slide 4 text

SYMFONY 4 MOTIVATION Or why the hell do we have to change things again https://www.flickr.com/photos/mindaugasdanys/3766009204

Slide 5

Slide 5 text

«As a developer, I want to start small, without too many dependencies. But I also want to be able to grow my application as I see fit. From a micro-framework style app to a gigantic monolith. Your choice. The framework should not get in the way.» Fabien Potencier «Symfony Flex is all about making it simple and easy to create any Symfony applications, from the most simple micro-style project to the more complex ones with dozens of dependencies. It automates adding and removing bundles. It takes care of giving you sensible defaults. It helps discovering good bundles.» Fabien Potencier

Slide 6

Slide 6 text

Victoria Quirante @vicqr [email protected] SF 4 seems like the result of a SWOT analysis Victoria Quirante @vicqr [email protected] S W O T Flexible Powerful Config time high Learning curve SF 2 Web development environment

Slide 7

Slide 7 text

Victoria Quirante @vicqr [email protected] Recent evolution of the web development environment Our favourite framework Some jQuery { { Back-end Front-end

Slide 8

Slide 8 text

Victoria Quirante @vicqr [email protected] Recent evolution of the web development environment Our favourite framework Some jQuery { { Back-end Front-end Backbone.js Ember.js Angular.js Gulp Grunt Vue.js Webpack React.js chats notifications immediate validations page reloads

Slide 9

Slide 9 text

Victoria Quirante @vicqr [email protected] Our favourite framework Some jQuery Recent evolution of the web development environment { { Back-end Front-end Our favourite front-end framework Our favourite back-end framework API Backbone.js Ember.js Angular.js Gulp Grunt Vue.js Webpack React.js chats notifications immediate validations page reloads

Slide 10

Slide 10 text

Victoria Quirante @vicqr [email protected] Our favourite framework Some jQuery Recent evolution of the web development environment { { Back-end Front-end Our favourite front-end framework Our favourite back-end framework API Our favourite front-end framework API

Slide 11

Slide 11 text

Victoria Quirante @vicqr [email protected] Our favourite framework Some jQuery Recent evolution of the web development environment { { Back-end Front-end Our favourite front-end framework Our favourite back-end framework API Our favourite front-end framework API API API API API

Slide 12

Slide 12 text

Then, what is expected from a back-end framework nowadays?

Slide 13

Slide 13 text

Victoria Quirante @vicqr [email protected] - To be a great solution for APIs - To make easy to build some functionalities (admin panels, etc.) - To be efficient creating small apps and microservices - ... What is expected nowadays from a back-end framework? To take good care of the back-end

Slide 14

Slide 14 text

Victoria Quirante @vicqr [email protected] SF 4 seems like the result of a SWOT analysis S W O T Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment

Slide 15

Slide 15 text

In front of this, what things should we change?

Slide 16

Slide 16 text

SYMFONY 4 PHILOSOPHY https://www.flickr.com/photos/68532869@N08/16357411958

Slide 17

Slide 17 text

Victoria Quirante @vicqr [email protected] Symfony roadmap

Slide 18

Slide 18 text

Victoria Quirante @vicqr [email protected] Symfony 2 was two things 1. A full stack framework 1. A full stack framework 2. A set of independent components

Slide 19

Slide 19 text

Victoria Quirante @vicqr [email protected] Symfony 2 was two things 1. A full stack framework But “developing in Symfony 2” generally meant using the full framework

Slide 20

Slide 20 text

Victoria Quirante @vicqr [email protected] Example: If you wanted to build a console app before You could start with the full FW and get many things you don’t need Or go for the components approach… and fight quite a bit

Slide 21

Slide 21 text

Victoria Quirante @vicqr [email protected] Symfony 2 VS Symfony 4 graphically SF 2 web app SF 2 API SF 2 microservice

Slide 22

Slide 22 text

Victoria Quirante @vicqr [email protected] Symfony 2 VS Symfony 4 graphically SF 2 web app SF 2 API SF 2 microservice SF 4 web app SF 4 API SF 4 microservice

Slide 23

Slide 23 text

Victoria Quirante @vicqr [email protected] Working with SF 4 SF 4 web app SF 4 API SF 4 microservice SF 4

Slide 24

Slide 24 text

SF4 is not a new FW, it is a new mindset behind the same FW

Slide 25

Slide 25 text

Victoria Quirante @vicqr [email protected] Symfony 4 - Compose your application Make easy to create projects with lots or few dependencies For that, they wanted automate bundle installation/configuration

Slide 26

Slide 26 text

It is key that we can make our project grow or shrink very easily

Slide 27

Slide 27 text

Victoria Quirante @vicqr [email protected] Working with SF 4 SF 4 web app SF 4 API SF 4 microservice SF 4 We need something to smooth out this transformations

Slide 28

Slide 28 text

SYMFONY FLEX What exactly is it

Slide 29

Slide 29 text

SF FLEX is not a version of SF, it is a tool to implement SF4’s philosophy

Slide 30

Slide 30 text

Victoria Quirante @vicqr [email protected] Symfony Flex - Automation to the max It is a composer plugin that comes with Symfony 4 Moving towards zero configuration time It also “promotes” a curated list of official recipes

Slide 31

Slide 31 text

Victoria Quirante @vicqr [email protected] Internals Modifies the behaviour of the require and update commands Allows Symfony to perform tasks before or after the Composer commands

Slide 32

Slide 32 text

Victoria Quirante @vicqr [email protected] How it works composer require mailer It installs and enables SwiftmailerBundle

Slide 33

Slide 33 text

Victoria Quirante @vicqr [email protected] How it works composer req mailer It installs and enables SwiftmailerBundle

Slide 34

Slide 34 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer

Slide 35

Slide 35 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Symfony Flex server Is there information about this package?

Slide 36

Slide 36 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Is there information about this package? Going for regular installation via Composer Nope Symfony Flex server

Slide 37

Slide 37 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Is there information about this package? Symfony Flex server

Slide 38

Slide 38 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Is there information about this package? Yes, sending recipe Cool, following recipe instructions! Symfony Flex server

Slide 39

Slide 39 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Is there information about this package? Yes, sending recipe Cool, following recipe instructions! Deciding which packages to install Symfony Flex server

Slide 40

Slide 40 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Is there information about this package? Asking Composer to install them Yes, sending recipe Cool, following recipe instructions! Deciding which packages to install Symfony Flex server

Slide 41

Slide 41 text

Victoria Quirante @vicqr [email protected] How it works Your application with Symfony Flex composer require mailer Is there information about this package? Asking Composer to install them Yes, sending recipe Cool, following recipe instructions! Deciding which packages to install Running any tasks required Symfony Flex server

Slide 42

Slide 42 text

Victoria Quirante @vicqr [email protected] Recipes Defined in a manifest.json file May contain other files or directories It ‘explains’ Symfony Flex what things need to be done

Slide 43

Slide 43 text

Victoria Quirante @vicqr [email protected] Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] }

Slide 44

Slide 44 text

Victoria Quirante @vicqr [email protected] Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] } Environments that this bundle has to enable automatically

Slide 45

Slide 45 text

Victoria Quirante @vicqr [email protected] Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] } Files and directories that will be copied into your application

Slide 46

Slide 46 text

Victoria Quirante @vicqr [email protected] Recipes { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] } New environment variables that will be added to your application

Slide 47

Slide 47 text

Victoria Quirante @vicqr [email protected] Recipes List of alternative shorter names for the package { "bundles": { "Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle": ["all"] }, "copy-from-recipe": { "config/": "%CONFIG_DIR%/" }, "env": { "MAILER_URL": "smtp://localhost:25?encryption=&auth_mode=" }, "aliases": ["mailer", "mail"] }

Slide 48

Slide 48 text

Victoria Quirante @vicqr [email protected] Official and unofficial recipes Two repositories: core and contrib official repository (very) opinionated approval from SF core team Symfony Flex looks here aliases core community repository not opinionated - Symfony Flex may look here - contrib

Slide 49

Slide 49 text

Victoria Quirante @vicqr [email protected] Creating a new Symfony app with Symfony Flex composer create-project symfony/skeleton my-project

Slide 50

Slide 50 text

Victoria Quirante @vicqr [email protected] Creating a new Symfony app with Symfony Flex composer create-project symfony/skeleton my-project "require": { "php": "^7.0.8", "symfony/flex": "^1.0", "symfony/console": "^4.0", "symfony/framework-bundle": "^4.0", "symfony/lts": "^4@dev", "symfony/yaml": "^4.0" }, Downloads the Symfony skeleton (just one composer.json)

Slide 51

Slide 51 text

Victoria Quirante @vicqr [email protected] Creating a new Symfony app with Symfony Flex composer create-project symfony/skeleton my-project "require": { "php": "^7.0.8", "symfony/flex": "^1.0", "symfony/console": "^4.0", "symfony/framework-bundle": "^4.0", "symfony/lts": "^4@dev", "symfony/yaml": "^4.0" }, Downloads the Symfony skeleton (just one composer.json) composer install symfony/flex is the first package installed And runs

Slide 52

Slide 52 text

Victoria Quirante @vicqr [email protected] May I avoid using Symfony Flex? Yes, you can install/configure things as you used to But Symfony Flex is the default way of doing things in Symfony 4

Slide 53

Slide 53 text

Victoria Quirante @vicqr [email protected] May I use Symfony Flex with an old project? Yes, but installing Symfony Flex is not enough You need to update the directory structure https://symfony.com/doc/master/setup/flex.html#upgrading-existing-applications-to-flex

Slide 54

Slide 54 text

WHAT HAS CHANGED Things we have to ‘relearn’ https://www.flickr.com/photos/vialbost/37167061631

Slide 55

Slide 55 text

Do you remember those never-ending discussions about one VS multiple bundle apps?

Slide 56

Slide 56 text

Guess what was the right answer…

Slide 57

Slide 57 text

«[...] We worked hard during the last few months to make sure that Symfony 4 can embrace bundle-less applications. So Symfony 4 will recommend and generate bundle-less applications.» Fabien Potencier

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

«[...] We worked hard during the last few months to make sure that Symfony 4 can embrace bundle-less applications. So Symfony 4 will recommend and generate bundle-less applications.» Fabien Potencier «No more bundle for your code, just use App\ as a namespace for any class under src/. It reduces the perceived complexity. It also makes your code feel more decoupled from Symfony.» Fabien Potencier

Slide 60

Slide 60 text

Victoria Quirante @vicqr [email protected] Bundle-less applications Change in best practices No more one-bundle-application Now zero-bundle-application is recommended In practice, not difficult to get used to this

Slide 61

Slide 61 text

Victoria Quirante @vicqr [email protected] Directory structure my-project/ ├── config/ │ ├── bundles.php │ ├── packages/ │ ├── routes.yaml │ └── services.yaml ├── public/ │ └── index.php ├── src/ │ ├── ... │ └── Kernel.php ├── templates/ └── vendor/ It may be a bit tricky at the beginning, but it is actually simpler

Slide 62

Slide 62 text

Victoria Quirante @vicqr [email protected] config/bundles.php File where installed bundles get referenced Symfony Flex is going to write here

Slide 63

Slide 63 text

Victoria Quirante @vicqr [email protected] config.yml -> packages/package-name.yaml Forget about the single long config file Now our configuration is splitted in different files One file per package/bundle and environment

Slide 64

Slide 64 text

Victoria Quirante @vicqr [email protected] parameters.yml -> Environment variables Now we have .env More standard way of managing settings # .env APP_ENV=dev APP_DEBUG=1 APP_SECRET=d5b7eb4ea25adca8c17bsdsc126831c DATABASE_URL="mysql://travolta:[email protected]:3306/travolta"#

Slide 65

Slide 65 text

Victoria Quirante @vicqr [email protected] Unified web front controller No more app.php and app_dev.php Just one (public/index.php) Trickier to switch between them But it is considered a better practice # public/index.php $kernel = new Kernel($_SERVER['APP_ENV'] ?? 'dev', $_SERVER['APP_DEBUG'] ?? false);

Slide 66

Slide 66 text

WHAT IS NEW What new shiny things do we get? https://www.flickr.com/photos/blondinrikard/14419731227

Slide 67

Slide 67 text

Of course, Symfony Flex, but what else?

Slide 68

Slide 68 text

Victoria Quirante @vicqr [email protected] Some key things already introduced in SF 3 - Automated configuration: - Autowiring - _defaults, _instanceof - Autoconfiguration - Further standardization: - PSR-4 based service discovery - PSR-11 containers - ... https://symfony.com/blog

Slide 69

Slide 69 text

Victoria Quirante @vicqr [email protected] Many not too flashy but yet powerful additions - Improvements in: - Guard authentication - Forms - Injection of tag services - Console exceptions - Overriding templates - ... - Integration with Bootstrap 4 form theme - ... https://symfony.com/blog

Slide 70

Slide 70 text

AND, finally, just when we had lost almost all hope...

Slide 71

Slide 71 text

A great solution for the assets

Slide 72

Slide 72 text

Victoria Quirante @vicqr [email protected] Webpack Encore It simplifies the integration of our Symfony project with Webpack Webpack is a great tool to process the assets Configuring Webpack is not easy But Webpack Encore solves that

Slide 73

Slide 73 text

DEMO TIME Let’s create a project with Symfony Flex https://www.flickr.com/photos/callmewhatever/30708918322

Slide 74

Slide 74 text

Victoria Quirante @vicqr [email protected] Let’s create a project with Symfony Flex We are going to create a project with API Platform and EasyAdmin

Slide 75

Slide 75 text

Victoria Quirante @vicqr [email protected] API Platform

Slide 76

Slide 76 text

Victoria Quirante @vicqr [email protected] EasyAdmin

Slide 77

Slide 77 text

Victoria Quirante @vicqr [email protected] composer create-project symfony/skeleton apiadmin-project cd apiadmin-project composer req api composer req admin composer req webserver - Create Entity - Config database bin/console doctrine:schema:update - Tell API Platform and EasyAdmin about our Entity bin/console server:run Demo time Let’s do it

Slide 78

Slide 78 text

EVALUATING How good are these changes?

Slide 79

Slide 79 text

Victoria Quirante @vicqr [email protected] Fair questions about SF 4 & SF Flex 1. Is it more difficult now to develop a ‘standard web project’? 2. Trying to make config extra simple… is it getting more obscure? 3. Are ‘official packages’ too promoted? Still early to know

Slide 80

Slide 80 text

Victoria Quirante @vicqr [email protected] The good It makes sense not to carry dependencies that you are not using The things we need to adapt to are not difficult Moving further towards standardization

Slide 81

Slide 81 text

Victoria Quirante @vicqr [email protected] The real good Trying to adapt to the upcoming challenges Webpack Encore Working together with the front-end, not fighting against it

Slide 82

Slide 82 text

BET 1: Let’s embrace the position of the back-end framework in the landscape, and try to adapt to our time BET 2: Let’s keep our Symfony as powerful and flexible, while trying to compete against more high-level-oriented solutions

Slide 83

Slide 83 text

Victoria Quirante @vicqr [email protected] Fears and hopes Great FW to create fully tailored-made apps SF It tries to gain ground on more high-level-oriented solutions It remains as good as always (or better) for that While making easier to build some “standard” stuff Optimistic outcome Pessimistic outcome It loses focus It loses love from traditional SF developers

Slide 84

Slide 84 text

FINAL THOUGHTS What to remember https://www.flickr.com/photos/dewalick/15842170328

Slide 85

Slide 85 text

Victoria Quirante @vicqr [email protected] To summarize S W O T Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment

Slide 86

Slide 86 text

Victoria Quirante @vicqr [email protected] To summarize S W O T Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment

Slide 87

Slide 87 text

Victoria Quirante @vicqr [email protected] To summarize S W O T Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment

Slide 88

Slide 88 text

Victoria Quirante @vicqr [email protected] To summarize S W O T Flexible Powerful Config times high Learning curve APIs everywhere Microservices needed Backends needed Drupal/Laravel Frontend revolution SF 2 Web development environment

Slide 89

Slide 89 text

Victoria Quirante @vicqr [email protected] To summarize Clear answer to the current times Imho, the direction taken looks promising There may be some risks, but it depends on how will it evolve The community has, of course, a lot to say in this

Slide 90

Slide 90 text

Thanks! Victoria Quirante @vicqr [email protected]