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
Andreas Hucks
October 09, 2013
Programming
15
1.7k
Best Practices in Symfony2
Andreas Hucks
October 09, 2013
Tweet
Share
More Decks by Andreas Hucks
See All by Andreas Hucks
Divide and Conquer (LonghornPHP 2019)
meandmymonkey
0
100
Symfony Internals
meandmymonkey
3
720
Divide and Conquer
meandmymonkey
1
600
Deptrac - Keep Your Architecture Clean
meandmymonkey
0
590
Introduction to Docker at PHPBenelux2015
meandmymonkey
3
780
Best Practices in Symfony2
meandmymonkey
0
320
Introduction to Docker at PHPNW2014
meandmymonkey
4
390
O(ops), Authentication!
meandmymonkey
4
770
Best Practices in Symfony2
meandmymonkey
28
4.5k
Other Decks in Programming
See All in Programming
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
受け取る人から提供する人になるということ
little_rubyist
0
250
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Ethereum_.pdf
nekomatu
0
470
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Featured
See All Featured
Designing Experiences People Love
moore
138
23k
How to Ace a Technical Interview
jacobian
276
23k
Adopting Sorbet at Scale
ufuk
73
9.1k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Bash Introduction
62gerente
608
210k
The World Runs on Bad Software
bkeepers
PRO
65
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Unsuck your backbone
ammeep
668
57k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Transcript
Best Practices in Symfony2 phpnw 2013 Manchester, Oct. 6th Andreas
Hucks Sonntag, 6. Oktober 13
@meandmymonkey Andreas Hucks Trainer & Consultant at Sonntag, 6. Oktober
13
Best Practices Sonntag, 6. Oktober 13
Bad Practices Sonntag, 6. Oktober 13
symfony Day 2009 Sonntag, 6. Oktober 13
Chapter One A Clean Project Sonntag, 6. Oktober 13
Naming Things in Symphony • Follow PSR-0, PSR-1, PSR-2 •
Find a common scheme for your team • Be explicit • Be consistent Sonntag, 6. Oktober 13
Care about your coding style • Again - follow PSR-0,
PSR-1, PSR-2 • Use PHPCSFixer http://goo.gl/tEK4y Sonntag, 6. Oktober 13
.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 Sonntag, 6. Oktober 13
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea should be in your global .gitignore Sonntag, 6. Oktober 13
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea probably this too Sonntag, 6. Oktober 13
.gitignore /web/bundles/ /app/bootstrap.php.cache /app/cache/* /app/config/parameters.yml /app/logs/* /build/ /vendor/ /bin/ /composer.phar
/data/uploads .idea this. Sonntag, 6. Oktober 13
Committing parameters.yml is a Three Kitten Offense Sonntag, 6. Oktober
13
Committing parameters.yml is a Three Kitten Offense Sonntag, 6. Oktober
13
Remove Acme\* Sonntag, 6. Oktober 13
Bundle Naming... Vendor\AwesomeBundle vs. Vendor\Bundle\AwesomeBundle Sonntag, 6. Oktober 13
Bundle Naming... Vendor\AwesomeBundle vs. Vendor\Bundle\AwesomeBundle Sonntag, 6. Oktober 13
FAIL a.k.a. „because I can“ • MyCompleteAppBundle (ok for small
projects) • MyAppNeedingGlobalResourcesBundle • MyBundleInsideAnotherBundleBundle Sonntag, 6. Oktober 13
What should go into a Bundle • Bundles should be
self-contained • Sets of Features • Examples: Forum, AdminPanel... • Configured in /app/config Sonntag, 6. Oktober 13
Your config options • YAML • XML • Annotations •
INI • PHP Sonntag, 6. Oktober 13
Your config options • YAML • XML • Annotations •
INI • PHP meh. Sonntag, 6. Oktober 13
Your config options • YAML • XML • Annotations •
INI • PHP special use cases Sonntag, 6. Oktober 13
Your config options • YAML • XML • Annotations •
INI • PHP not for everything Sonntag, 6. Oktober 13
Your config options • YAML • XML • Annotations •
INI • PHP Routing, Bundle Config, Parameters Services Validators, ORM/ODM Sonntag, 6. Oktober 13
Nest your routing files Sonntag, 6. Oktober 13
Chapter Two Controllers Sonntag, 6. Oktober 13
• Put Controllers on a Diet • Decouple them Sonntag,
6. Oktober 13
Try to lose the Boilerplate Sonntag, 6. Oktober 13
@Template([name]) Sonntag, 6. Oktober 13
@Cache(...) Sonntag, 6. Oktober 13
Inject the Request into Controllers Sonntag, 6. Oktober 13
New in 2.3: handleRequest() Sonntag, 6. Oktober 13
Events for add-on actions Sonntag, 6. Oktober 13
Service Layers Sonntag, 6. Oktober 13
Service Layers Sonntag, 6. Oktober 13
Using the BaseController? Wrap calls to the Container Sonntag, 6.
Oktober 13
Chapter Three Dependency Injection Sonntag, 6. Oktober 13
Injecting the Container Sonntag, 6. Oktober 13
Injecting the Container Sonntag, 6. Oktober 13
But... but Symfony is doing it! Sonntag, 6. Oktober 13
...\TwigBundle\Extension\AssetsExtension Sonntag, 6. Oktober 13
It‘s because of Scopes! Sonntag, 6. Oktober 13
Solution: Synchronized Services (>= 2.3) Sonntag, 6. Oktober 13
Alternative: Providing the Request (< 2.3) Sonntag, 6. Oktober 13
Alternative: Providing the Request (< 2.3) Sonntag, 6. Oktober 13
Service Organization Sonntag, 6. Oktober 13
Split up Service Definitions Sonntag, 6. Oktober 13
Dynamic Loading of Service Definitions Sonntag, 6. Oktober 13
Use Semantic Configuration! Sonntag, 6. Oktober 13
The Container as a Registry Sonntag, 6. Oktober 13
The Container as a Registry Sonntag, 6. Oktober 13
Instead: Proper Service Configuration Sonntag, 6. Oktober 13
Binding to the Environment Sonntag, 6. Oktober 13
Binding to the Environment Sonntag, 6. Oktober 13
Instead: Use Your config files Sonntag, 6. Oktober 13
Miscellaneous • Use XML for Service Definitions • Remember you
can use Environment Variables (Apache, Nginx, ...) • Use %kernel.root_dir% as a reference Sonntag, 6. Oktober 13
Intermezzo Random Tips Sonntag, 6. Oktober 13
PHP • Use 5.4/5.5, it‘s faster • Use APC (or
one of the alternatives) Sonntag, 6. Oktober 13
Composer • Use the --optimize-autoloader option Sonntag, 6. Oktober 13
Doctrine • Activate Metadata Cache • Activate Query Cache •
Use factory-service to register Repositories & ObjectManagers as Services • Do NOT inject the EntityManager into your entities Sonntag, 6. Oktober 13
Security • Make sure there are no leaks in the
security.yml access_control section! • Better: Check Authorization in Controller, possibly use JMSSecurityExtraBundle Sonntag, 6. Oktober 13
Translation • Work with translation keys instead of full text
to avoid breaking translations Sonntag, 6. Oktober 13
Searching • Look for „Symfony2“ (without the space) Sonntag, 6.
Oktober 13
Read the Documentation (and the Changelogs) Sonntag, 6. Oktober 13
Chapter Four Forms Sonntag, 6. Oktober 13
Forms in Controllers Sonntag, 6. Oktober 13
Forms in Controllers Sonntag, 6. Oktober 13
• Couples Form setup to Controller • No reusability Sonntag,
6. Oktober 13
Better: Use Type Classes Sonntag, 6. Oktober 13
Always set the data_class Sonntag, 6. Oktober 13
Using Data in Constructors Sonntag, 6. Oktober 13
Using Data in Constructors Sonntag, 6. Oktober 13
Use Form Events for Related Data Sonntag, 6. Oktober 13
Define Types as Services Sonntag, 6. Oktober 13
Define Types as Services Sonntag, 6. Oktober 13
Don‘t disable CSRF Sonntag, 6. Oktober 13
Don‘t disable CSRF Sonntag, 6. Oktober 13
Thanks! Questions? Please give feedback: http://goo.gl/yK97XK Sonntag, 6. Oktober 13