SlideShare a Scribd company logo
A dive into
Symfony 4
A long time ago...
Symfony 2 was born
Key Concepts
Components

Bundles

Distributions
Time passed by...
How did it go?
Bene... ma non benissimo :-(
Bene... ma non benissimo :-(
Distributions
Initial idea: one distribution per app type

• Standard Distribution

• Rest Distribution

• Cms Distribution

• ...
Distributions
In Reality: distributions never took off, everybody uses
Standard Distribution and removes stuff manually
Bundles
Initial Idea: organise reusable code in
bundles
Bundles
Have you ever seen this organisation?
ShopBundle

CmsBundle

AdminBundle

...
Bundles
Have you ever seen this organisation?
ShopBundle

CmsBundle

AdminBundle

Common|General| ... | Bundle
Bundles
Vendor code is reusable

Your App code is not
Bundles
Installing/Removing a Bundle is mostly a manual operation

# composer require/remove <bundle>

# add/remove to AppKernel.php

# add/remove configurations
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
DX initiative
Symfony has a steep learning curve compared to other
frameworks 

The Developer eXperience initiative aims to create a
better user experience
Symfony 4 was born...
New Directory Structure
New Directory Structure
The idea behind that is to have a more
intuitive structure
A dive into Symfony 4
New Directory Structure
bin

config

public 

src

var

vendor
New Directory Structure
bin

config

public 

src

var

vendor
index.php
...
favicon.ico
robots.txt
bundles
New Directory Structure
bin

config

public 

src

var

vendor
cache/
log/
session/
New Directory Structure
bin

config

public 

src

var

vendor
Kernel.php
Entity
Repository
Command
Controller
...
No Bundles!
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
return [

SymfonyBundleFrameworkBundleFrameworkBundle::class => ['all' => true],

SymfonyBundleWebServerBundleWebServerBundle::class => ['dev' => true],

SymfonyBundleMakerBundleMakerBundle::class => ['dev' => true],

SymfonyBundleDebugBundleDebugBundle::class => ['dev' => true, 'test' => true],

SymfonyBundleSecurityBundleSecurityBundle::class => ['all' => true],

];
New Directory Structure
assets

bin

data

config

public 

src

templates

tests

translations

var

vendor
Where is parameter.yaml?
Environment Variables
Environment Variables
Symfony already has them eg.
SYMFONY__ENV
Environment Variables
Now resolved at runtime! You can change
them without touching the app

https://www.12factor.net/config
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
.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 ###
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));
Symfony Flex
Flex
A new way to create and evolve a Symfony application

Composition over inheritance

Start small and add what you need
Flex
Integrates into composer workflow 

Automates bundles installation and configuration
Flex
Flex
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
symfony.sh
recipes
https://github.com/symfony/recipes 

https://github.com/symfony/recipes-contrib
alias
orm, twig, security, form, validation, ...
So long Standard Edition...
composer require symfony/website-skeleton
composer require symfony/skeleton
So long Silex...
https://symfony.com/blog/the-end-of-silex
Other Bits...
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
Autowiring
Wait 5 minutes... :-P
composer require make
MakerBundle
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
Fastest PHP Router
https://symfony.com/blog/new-in-symfony-4-1-fastest-php-router
VarDumper Server
https://symfony.com/blog/new-in-symfony-4-1-vardumper-server
Messenger Component
https://symfony.com/blog/new-in-symfony-4-1-messenger-component
Panther
https://symfony.com/blog/introducing-symfony-panther-a-browser-
testing-and-web-scrapping-library-for-php
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
Thank you!
Michele Orselli
_orso_
micheleorselli / ideatosrl
mo@ideato.it
https://joind.in/talk/2a90f

More Related Content

PDF
Symfony 4 Workshop - Limenius
PDF
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
PDF
Elixir/OTP for PHP developers
PDF
Symfony 2
PDF
Sylius and Api Platform The story of integration
PDF
Always up to date, testable and maintainable documentation with OpenAPI
PDF
Curso Symfony - Clase 4
PDF
Symfony tips and tricks
Symfony 4 Workshop - Limenius
New Symfony Tips & Tricks (SymfonyCon Paris 2015)
Elixir/OTP for PHP developers
Symfony 2
Sylius and Api Platform The story of integration
Always up to date, testable and maintainable documentation with OpenAPI
Curso Symfony - Clase 4
Symfony tips and tricks

What's hot (20)

PDF
Symfony2 revealed
PDF
Symfony & Javascript. Combining the best of two worlds
PDF
Extending Twig
PDF
Curso Symfony - Clase 2
PDF
What's new with PHP7
PDF
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
PDF
Dependency Injection in PHP
PDF
Creating and Maintaining WordPress Plugins
PDF
Mastering Twig (DrupalCon Barcelona 2015)
PPTX
Zero to SOLID
PDF
symfony on action - WebTech 207
PDF
関西PHP勉強会 php5.4つまみぐい
PDF
Object Oriented Programming for WordPress Plugin Development
PDF
Jumping Into WordPress Plugin Programming
PDF
November Camp - Spec BDD with PHPSpec 2
PPTX
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
PDF
A Dexterity Intro for Recovering Archetypes Addicts
PDF
sfDay Cologne - Sonata Admin Bundle
ODP
Mastering Namespaces in PHP
PDF
PHP traits, treat or threat?
Symfony2 revealed
Symfony & Javascript. Combining the best of two worlds
Extending Twig
Curso Symfony - Clase 2
What's new with PHP7
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Dependency Injection in PHP
Creating and Maintaining WordPress Plugins
Mastering Twig (DrupalCon Barcelona 2015)
Zero to SOLID
symfony on action - WebTech 207
関西PHP勉強会 php5.4つまみぐい
Object Oriented Programming for WordPress Plugin Development
Jumping Into WordPress Plugin Programming
November Camp - Spec BDD with PHPSpec 2
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
A Dexterity Intro for Recovering Archetypes Addicts
sfDay Cologne - Sonata Admin Bundle
Mastering Namespaces in PHP
PHP traits, treat or threat?
Ad

Similar to A dive into Symfony 4 (20)

PDF
Symfony quick tour_2.3
PDF
Symfony finally swiped right on envvars
PDF
Symfony 4: A new way to develop applications #phpsrb
PDF
Symfony 4: A new way to develop applications #ipc19
PDF
Symfony tips and tricks
ODP
Running Symfony
PDF
Hands-on with the Symfony2 Framework
PDF
Symfony: Your Next Microframework (SymfonyCon 2015)
PPT
Symfony: A Brief Introduction
PDF
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
PDF
Symfony4 - Deep dive
PPT
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
PDF
Symfony2 San Francisco Meetup 2009
PPTX
Dev traning 2016 symfony
PDF
Symfony internals [english]
PDF
Symfony4: A new way to develop applications | Antonio Peric | CODEiD
PDF
Create a Symfony Application from a Drupal Perspective
PDF
Fabien Potencier "Symfony 4 in action"
DOCX
Installing symfony within netbeans and WAMP
ODP
An introduction to Symfony 2 for symfony 1 developers
Symfony quick tour_2.3
Symfony finally swiped right on envvars
Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #ipc19
Symfony tips and tricks
Running Symfony
Hands-on with the Symfony2 Framework
Symfony: Your Next Microframework (SymfonyCon 2015)
Symfony: A Brief Introduction
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
Symfony4 - Deep dive
Workshop: Symfony2 Intruduction: (Controller, Routing, Model)
Symfony2 San Francisco Meetup 2009
Dev traning 2016 symfony
Symfony internals [english]
Symfony4: A new way to develop applications | Antonio Peric | CODEiD
Create a Symfony Application from a Drupal Perspective
Fabien Potencier "Symfony 4 in action"
Installing symfony within netbeans and WAMP
An introduction to Symfony 2 for symfony 1 developers
Ad

More from Michele Orselli (20)

PDF
Tackling Tech Debt with Rector
PDF
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
PDF
A recommendation engine for your applications codemotion ams
PDF
A recommendation engine for your applications phpday
PDF
Hopping in clouds - phpuk 17
PDF
A recommendation engine for your php application
PDF
Symfony e micro (non così tanto) services
PDF
Hopping in clouds: a tale of migration from one cloud provider to another
PDF
Vagrant for real (codemotion rome 2016)
PDF
Vagrant for real codemotion (moar tips! ;-))
PDF
Migrare a Symfony 3
PDF
Vagrant for real
PDF
Implementing data sync apis for mibile apps @cloudconf
PDF
Server side data sync for mobile apps with silex
PDF
Continuous, continuous, continuous
PDF
Deploy a PHP App on Google App Engine
PDF
Implementing Server Side Data Synchronization for Mobile Apps
PDF
Deploy a php app on Google App Engine
PDF
PDF
Manage a project portfolio
Tackling Tech Debt with Rector
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
A recommendation engine for your applications codemotion ams
A recommendation engine for your applications phpday
Hopping in clouds - phpuk 17
A recommendation engine for your php application
Symfony e micro (non così tanto) services
Hopping in clouds: a tale of migration from one cloud provider to another
Vagrant for real (codemotion rome 2016)
Vagrant for real codemotion (moar tips! ;-))
Migrare a Symfony 3
Vagrant for real
Implementing data sync apis for mibile apps @cloudconf
Server side data sync for mobile apps with silex
Continuous, continuous, continuous
Deploy a PHP App on Google App Engine
Implementing Server Side Data Synchronization for Mobile Apps
Deploy a php app on Google App Engine
Manage a project portfolio

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
A Presentation on Artificial Intelligence
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Big Data Technologies - Introduction.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Network Security Unit 5.pdf for BCA BBA.
A Presentation on Artificial Intelligence
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
20250228 LYD VKU AI Blended-Learning.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Big Data Technologies - Introduction.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm

A dive into Symfony 4