Slide 1

Slide 1 text

42 best practices for Symfony, a decade later Tugdual Saunier

Slide 2

Slide 2 text

Tugdual Saunier / @tucksaun / [email protected] Back in time

Slide 3

Slide 3 text

Tugdual Saunier / @tucksaun / [email protected] https://www.goodfon.com/new-year/wallpaper-2013-novyy-god-prazdnik-iskry.html

Slide 4

Slide 4 text

Tugdual Saunier / @tucksaun / [email protected] Some events that were regional …

Slide 5

Slide 5 text

Tugdual Saunier / @tucksaun / [email protected] … became international

Slide 6

Slide 6 text

Tugdual Saunier / @tucksaun / [email protected] Some topics became more trendy DevOps Micro Services Docker IA

Slide 7

Slide 7 text

Tugdual Saunier / @tucksaun / [email protected] And some new ones emerged Chat GPT

Slide 8

Slide 8 text

Tugdual Saunier / @tucksaun / [email protected] Some things didn ’ t really change …

Slide 9

Slide 9 text

Tugdual Saunier / @tucksaun / [email protected] … but some are

Slide 10

Slide 10 text

Tugdual Saunier / @tucksaun / [email protected] Designs evolved

Slide 11

Slide 11 text

Tugdual Saunier / @tucksaun / [email protected] Designs evolved

Slide 12

Slide 12 text

Tugdual Saunier / @tucksaun / [email protected] Devices evolved

Slide 13

Slide 13 text

Tugdual Saunier / @tucksaun / [email protected] Usages radically changed

Slide 14

Slide 14 text

Tugdual Saunier / @tucksaun / [email protected] Bitcoin skyrocketed

Slide 15

Slide 15 text

Tugdual Saunier / @tucksaun / [email protected] https://speakerdeck.com/tucksaun/42-best-practices-for-symfony2 https://speakerdeck.com/tucksaun/42-bonnes-pratique-pour- symfony2 Translated for the occasion so that you can go back in time if you wish 🤓

Slide 16

Slide 16 text

Tugdual Saunier / @tucksaun / [email protected] Agenda https://www.flickr.com/photos/internetarchivebookimages/14596082918/ • Obsolete practices • Up-to-date practices • Adjusted practices • New practices

Slide 17

Slide 17 text

Tugdual Saunier / @tucksaun / [email protected] Disclaimer Generated using Adobe Firefly

Slide 18

Slide 18 text

Tugdual Saunier / @tucksaun / [email protected] Obsoletes practices https://commons.wikimedia.org/wiki/File:Hindenburg_burning.jpg

Slide 19

Slide 19 text

Tugdual Saunier / @tucksaun / [email protected] “No official best practices” Back in 2013, there was no official best practices list. This is not the case anymore: https://symfony.com/doc/ current/best_practices.html

Slide 20

Slide 20 text

Tugdual Saunier / @tucksaun / [email protected] “Symfony2” No, not anymore 😅 “Use Symfony2 (capitalized, no space) when you are looking for documentation or seeking help”

Slide 21

Slide 21 text

Tugdual Saunier / @tucksaun / [email protected] Bootstrapping / Structure Well, well, well… Flex has been a game changer and the "skeleton" is now an empty shell. “Use the Standard Edition. But do some house cleaning!”

Slide 22

Slide 22 text

Tugdual Saunier / @tucksaun / [email protected] Bootstrapping / Structure Also, there is now an official symfony tool that can be used to bootstrap a project symfony new

Slide 23

Slide 23 text

Tugdual Saunier / @tucksaun / [email protected] Bootstrapping / Structure Does not even exist anymore 😂 “Don't deploy app_dev.php”

Slide 24

Slide 24 text

Tugdual Saunier / @tucksaun / [email protected] Assets 🙊 “Use Assetic”

Slide 25

Slide 25 text

Tugdual Saunier / @tucksaun / [email protected] Up-to-date
 practices https://www.flickr.com/photos/harry_nl/30761967444

Slide 26

Slide 26 text

Tugdual Saunier / @tucksaun / [email protected] Documentation “Read it. Read it again.”

Slide 27

Slide 27 text

Tugdual Saunier / @tucksaun / [email protected] Coding Style “A must-have tool is available to help your to respect Symfony's coding style: PHP Coding Standards Fixer (cs.symfony.com)” It's funny to see that this tool is still around!

Slide 28

Slide 28 text

Tugdual Saunier / @tucksaun / [email protected] Semantic configuration “Use Semantic Configuration for your application. This is useful to validate configuration during cache warmup and display meaningful error messages.”

Slide 29

Slide 29 text

Tugdual Saunier / @tucksaun / [email protected] Controllers “No business logic in controllers.”

Slide 30

Slide 30 text

Tugdual Saunier / @tucksaun / [email protected] Forms “Build your form in Form Types.” “Always redirect the user after a successful form processing in POST.”

Slide 31

Slide 31 text

Tugdual Saunier / @tucksaun / [email protected] Doctrine “Queries must be created in dedicated classes (Repository), not directly in controllers/services.” “Use your entities to store data. Use dedicated business classes to manipulate them.” “Enable metadata and query caches.”

Slide 32

Slide 32 text

Tugdual Saunier / @tucksaun / [email protected] Tests “Test your application. Use unit AND functional tests (at least).”

Slide 33

Slide 33 text

Tugdual Saunier / @tucksaun / [email protected] Logging “Do not refrain yourself to log.” “Monolog's default configuration is really good for production.”

Slide 34

Slide 34 text

Tugdual Saunier / @tucksaun / [email protected] Profiler “The Web Debug Toolbar gives you a lot of useful informations. Always keep an eye on it.”

Slide 35

Slide 35 text

Tugdual Saunier / @tucksaun / [email protected] Commands “Use Commands for your batch processing and repetitive tasks.”

Slide 36

Slide 36 text

Tugdual Saunier / @tucksaun / [email protected] PHP “Use PHP 5.4” Time flies 😂 Should have been phrased as “use the latest available version” but the idea behind still stands

Slide 37

Slide 37 text

Tugdual Saunier / @tucksaun / [email protected] Finally “Do not forget that Symfony is a PHP Object Framework.”

Slide 38

Slide 38 text

Tugdual Saunier / @tucksaun / [email protected] Finally Symfony is not dogmatic … be pragmatic

Slide 39

Slide 39 text

Tugdual Saunier / @tucksaun / [email protected] Slightly adjusted
 practices https://1x.com/photo/914233

Slide 40

Slide 40 text

Tugdual Saunier / @tucksaun / [email protected] Bundles Back in 2013, organising your code in Bundles was a challenge and the source of a lot of questioning. The tips evoked at this moment are still relevant but only for specific use cases.

Slide 41

Slide 41 text

Tugdual Saunier / @tucksaun / [email protected] Dependency Injection Container (DIC) But today, the Autowiring changed the game and the pure DIC experience is mostly needed for advanced use cases “The DIC is without any doubts the most powerful tool in Symfony. Symfony flexibility comes from the DIC.”

Slide 42

Slide 42 text

Tugdual Saunier / @tucksaun / [email protected] DIC The Autowiring makes your life easier. Use it! But look at what happens behind the scenes.

Slide 43

Slide 43 text

Tugdual Saunier / @tucksaun / [email protected] Your credentials are sensitive! We now also have Secrets 🦹 Have a look at them • Do not hardcode credentials in configuration: use parameters • Do not version parameters.[ini|yml] • Use environment variables

Slide 44

Slide 44 text

Tugdual Saunier / @tucksaun / [email protected] Views Twig is the only templating engine available natively today. So the recommendation to use it still stands, but you have less choice 😆 “Use Twig”

Slide 45

Slide 45 text

Tugdual Saunier / @tucksaun / [email protected] Security Don’t forget about Voters.

Slide 46

Slide 46 text

Tugdual Saunier / @tucksaun / [email protected] New
 practices https://www.flickr.com/photos/spacex/52553312005/

Slide 47

Slide 47 text

Tugdual Saunier / @tucksaun / [email protected] Docker Use Docker (or a similar tech) in order to get a reproductible stack.

Slide 48

Slide 48 text

Tugdual Saunier / @tucksaun / [email protected] API Don’t reinvent the wheel Use API Platform

Slide 49

Slide 49 text

Tugdual Saunier / @tucksaun / [email protected] Assets Use AssetMapper

Slide 50

Slide 50 text

Tugdual Saunier / @tucksaun / [email protected] Workflow Don’t forget about the Workflow component

Slide 51

Slide 51 text

Tugdual Saunier / @tucksaun / [email protected] Messenger Use Messenger early on (even for synchronous handling). Consider moving to async background handling.

Slide 52

Slide 52 text

Tugdual Saunier / @tucksaun / [email protected] Scheduler Combine Console + Messenger + Scheduler This is a really powerful combo, your logic can then be easily triggered either: • from the web • on a regular basis • manually using the command line

Slide 53

Slide 53 text

Tugdual Saunier / @tucksaun / [email protected] Embrace the small iterative changes Apply minor version upgrades early on! Symfony now has the BC promise. This means the minor version upgrades are safe. They will bring you new features without breaking changes.

Slide 54

Slide 54 text

Tugdual Saunier / @tucksaun / [email protected] Prepare for bigger changes With minor version upgrades you will gain deprecations notices and BC layer. So you can migrate to new ways of doing things earlier and little by little

Slide 55

Slide 55 text

Tugdual Saunier / @tucksaun / [email protected] Embrace the bigger changes For smooth major version upgrades: Monitor the deprecations reporting and clean them little by little Use Rector Have tests Follow best practices 🤓

Slide 56

Slide 56 text

Tugdual Saunier / @tucksaun / [email protected] Conclusion https://www.flickr.com/photos/spacex/51027443336/

Slide 57

Slide 57 text

Tugdual Saunier / @tucksaun / [email protected] Conclusion https://www.vecteezy.com/photo/26975988-a-worker-s-hands-hard-work-and-dedication-that-goes-into-their-craft-labor-day-ai-generative

Slide 58

Slide 58 text

Tugdual Saunier / @tucksaun / [email protected] Conclusion https://www.esa.int/ESA_Multimedia/Images/2021/11/Cosmic_pearl

Slide 59

Slide 59 text

Tugdual Saunier / @tucksaun / [email protected] Conclusion https://concord.fandom.com/wiki/Interstellar_Spaceship_Names?file=Interstellar_spaceship.jpg

Slide 60

Slide 60 text

Tugdual Saunier / @tucksaun / [email protected] Conclusion https://www.deviantart.com/glennclovis/art/Phoenix-Station-415020946

Slide 61

Slide 61 text

Tugdual Saunier / @tucksaun / [email protected] @tucksaun [email protected]