Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Best Practices in Symfony2
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Andreas Hucks
June 04, 2013
Programming
28
4.6k
Best Practices in Symfony2
Given at International PHP Conference 2013
Andreas Hucks
June 04, 2013
Tweet
Share
More Decks by Andreas Hucks
See All by Andreas Hucks
Divide and Conquer (LonghornPHP 2019)
meandmymonkey
0
180
Symfony Internals
meandmymonkey
3
920
Divide and Conquer
meandmymonkey
1
710
Deptrac - Keep Your Architecture Clean
meandmymonkey
0
760
Introduction to Docker at PHPBenelux2015
meandmymonkey
3
890
Best Practices in Symfony2
meandmymonkey
0
490
Introduction to Docker at PHPNW2014
meandmymonkey
4
420
O(ops), Authentication!
meandmymonkey
4
1k
Best Practices in Symfony2
meandmymonkey
15
1.8k
Other Decks in Programming
See All in Programming
Apache Iceberg V3 and migration to V3
tomtanaka
0
150
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
940
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
110
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
AI時代の認知負荷との向き合い方
optfit
0
150
Fragmented Architectures
denyspoltorak
0
150
CSC307 Lecture 08
javiergs
PRO
0
670
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
Featured
See All Featured
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
280
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
930
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
120
The Curious Case for Waylosing
cassininazir
0
230
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
350
The Cult of Friendly URLs
andyhume
79
6.8k
A better future with KSS
kneath
240
18k
The SEO identity crisis: Don't let AI make you average
varn
0
67
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
430
Practical Orchestrator
shlominoach
191
11k
Transcript
Best Practices in Symfony2 IPC Spring 2013 Berlin, June 4th
Andreas Hucks
@meandmymonkey Andreas Hucks Trainer & Consultant at SensioLabs Deutschland
Best Practices
Bad Practices
symfony Day 2009
Chapter One A Clean Project
Naming Things in Symphony • Follow PSR-0, PSR-1, PSR-2 •
Find a common scheme for your team • Be explicit • Be consistent
Care about your coding style • Again - follow PSR-0,
PSR-1, PSR-2 • Use PHPCSFixer http://goo.gl/tEK4y
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea add your own
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea should to be in your global .gitignore
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea maybe this too
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea this.
Committing parameters.yml is a Three Kitten Offense
Remove Acme\*
Bundle Naming... Vendor\AwesomeBundle vs. Vendor\Bundle\AwesomeBundle
Bundle Naming Vendor\AwesomeBundle vs. Vendor\Bundle\AwesomeBundle
FAIL a.k.a. „because I can“ • MyCompleteAppBundle (ok for small
projects) • MyAppNeedingGlobalResourcesBundle • MyBundleInsideAnotherBundleBundle
What should go into a Bundle • Bundles should be
self-contained • Sets of Features • Examples: Forum, AdminPanel... • Configured in /app/config
Your config options • YAML • XML • Annotations •
INI • PHP
Your config options • YAML • XML • Annotations •
INI • PHP meh.
Your config options • YAML • XML • Annotations •
INI • PHP special use cases
Your config options • YAML • XML • Annotations •
INI • PHP not for everything
Your config options • YAML • XML • Annotations •
INI • PHP Routing, Bundle Config, Parameters Services Validators, ORM/ODM
Nest your routing files
Chapter Two Controllers
• Put Controllers on a Diet • Decouple them
Try to lose the Boilerplate
@Template([name])
@Cache(...)
Inject the Request into Controllers
New in 2.3: handleRequest()
Events for add-on actions
Persistence Handlers
Persistence Handlers
Using the BaseController? Wrap calls to the Container
Chapter Three Dependency Injection
Injecting the Container
But... but Symfony is doing it!
...\TwigBundle\Extension\AssetsExtension
It‘s because of Scopes!
Solution: Synchronized Services (>= 2.3)
Alternative: Providing the Request (< 2.3)
Alternative: Providing the Request (< 2.3)
Service Organization
Split up Service Definitions
Dynamic Loading of Service Definitions
Use Semantic Configuration!
The Container as a Registry
Instead: Proper Service Configuration
Binding to the Environment
Instead: Use Your config files
Miscellaneous • Use XML for Service Definitions • Remember you
can use Environment Variables (Apache, Nginx, ...) • Use %kernel.root_dir% as a reference
Intermezzo Random Tips
PHP • Use 5.4, it‘s faster • Use APC (or
one of the alternatives)
Composer • Use the --optimize-autoloader option
Doctrine • Activate Metadata Cache • Activate Query Cache •
Use factory-service to register Repositories & ObjectManagers as Services
Security • Make sure there are no leaks in the
security.yml access_control section! • Better: Check Authorization in Controller, possibly use SecurityExtraBundle
Translation • Work with translation keys instead of full text
to avoid breaking translations
Searching • Look for „Symfony2“ (without the space)
Read the Documentation (and the Changelogs)
Chapter Four Forms
Forms in Controllers
• Couples Form setup to Controller • No reusability
Better: Use Type Classes
Always set the data_class
Using Data in Constructors
Use Form Events for Related Data
Define Types as Services
Define Types as Services
Don‘t disable CSRF
Thanks! Questions? Please give feedback: http://goo.gl/kwEqY