how symfony changed my life
TRANSCRIPT
![Page 1: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/1.jpg)
Matthias Noback Lelystad, September 1st 2015
10
years!
How Symfony changed my life
![Page 2: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/2.jpg)
Pre-symfony
![Page 3: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/3.jpg)
From ASP using VBScript and a MS Access database
To PHP with a MySQL database
"You should try PHP!"
![Page 4: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/4.jpg)
From include('script.php')
To proper function calls
![Page 5: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/5.jpg)
From PHP 4 and one mega Page class
To PHP 5 with proper scoping for methods and properties, and autoloading
![Page 6: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/6.jpg)
From PHP & HTML in the same file
To PHP classes and Smarty template files
![Page 7: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/7.jpg)
From copying snippets from the Internet
To downloading single-purpose libraries
![Page 8: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/8.jpg)
Feeling mighty fine
SQL injection
Register globals
Session hijacking
Magic quotes
CSRF
XSS
![Page 9: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/9.jpg)
Basically...
![Page 10: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/10.jpg)
But... performance was very good ;)
![Page 11: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/11.jpg)
Driebit (2008)
![Page 12: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/12.jpg)
symfony (1)with a lower-case s
![Page 13: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/13.jpg)
Symfony Camp (2007)
Stefan Koopmanschap
![Page 14: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/14.jpg)
The Book (back then)
François Zaninotto(Propel)
symfony 1.1
![Page 15: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/15.jpg)
Working with symfony 1 meant...
MVC
Fat controllers
Fat models
(Zend devs wrote fat services as well)
![Page 16: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/16.jpg)
Not in the controller or the model?
Put it in:
A "peer" class
A utility class
Or: create a global singleton for it
![Page 17: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/17.jpg)
What's a singleton?
Static
Global
Single instance
class Singleton{ private static $instance; private function __construct() { } public static function getInsta
nce()
{ if (self::$instance === nul
l) {
self::$instance = new self();
} return self::$instance; }}
![Page 18: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/18.jpg)
God object
sfContext::getInstance()
getUser(), getResponse(), getRequest(), getLogger(), getI18N(), ...
![Page 19: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/19.jpg)
Just reach out
![Page 20: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/20.jpg)
Why bad?
Testability
Isolation
Side-effects
Configuration
No separation of concerns
![Page 21: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/21.jpg)
CTO at SensioLabs DE
![Page 22: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/22.jpg)
Pushing the limits
![Page 23: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/23.jpg)
Tweaking symfony
Event listeners: add missing methods on the fly (!)
Filters: chain of responsibility
factories.yml and other config files
![Page 24: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/24.jpg)
Switch to Doctrine
It was... new
version 1.0
![Page 25: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/25.jpg)
Develop some Plugins
![Page 26: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/26.jpg)
Learn about advanced topics
Emails
Forms
Doctrine
Internals
![Page 27: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/27.jpg)
SymfonyLive Paris 2010
Revealing Symfony2
![Page 28: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/28.jpg)
SymfonyLive Paris 2011
Almost releasing Symfony 2.0
Excitement all over the place
![Page 29: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/29.jpg)
Start using 2.0?
No backwards compatibility
No best practices
No CMS
![Page 30: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/30.jpg)
Not even...
... an admin
generator
only for scaffolding ;)
![Page 31: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/31.jpg)
Migrating to 2.0?
Company owners didn't dare to take the step (I agree with them now!)
I left the company :)
![Page 32: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/32.jpg)
Symfony2
capital "S"
no space, for Google
![Page 33: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/33.jpg)
Infrastructure
1. Git for version control
2. Install script or Git submodules for vendor code
3. At some point: composer started handling dependencies
![Page 34: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/34.jpg)
TemplatingTwig:
Own syntax
No PHP code
"Auto-safe"
Fast (the engine that is)
"Templating engines in PHP" by Fabien Potencier
![Page 35: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/35.jpg)
Dependency injection container
Major improvement: everything can be configured
No runtime resolvers anymore
![Page 36: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/36.jpg)
What's dependency injection?
class Foo{ private $bar; public function __construct(Bar
$bar)
{ $this->bar = $bar; }}
![Page 37: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/37.jpg)
What's a DI container?
class Container{ public function createFoo() { return new Foo($this->getBar()); } private function createBar() { return new Bar(); }}
![Page 38: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/38.jpg)
What does DI give us?
Single responsibility
Testability
Dependency inversion
SpeedFlexibility
![Page 39: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/39.jpg)
Active record -> data mapper
Doctrine 1/Propel
Doctrine 2/...
![Page 40: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/40.jpg)
Active record sample
class Invoice extends Record{ } $invoice = new Invoice();$invoice->save();
![Page 41: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/41.jpg)
Data mapper sample
class Invoice{ } $invoice = new Invoice();$entityManager->persist($invoice);
POPO
![Page 42: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/42.jpg)
Why is that better?
Isolation
Model first
Decoupling (not always a good reason)
![Page 43: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/43.jpg)
Bundle ~= Plugin
![Page 44: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/44.jpg)
First-class citizens
![Page 45: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/45.jpg)
A bundle for each feature
![Page 46: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/46.jpg)
Framework coupling
Libraries are framework-independent
Bundles are explicitly meant to couple code to the framework
![Page 47: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/47.jpg)
Bundles: service definitions
Service definition files
Bundle extension
Bundle configuration
Compiler pass
![Page 48: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/48.jpg)
Bundle: root for resources
@MyBundle/Resources/views/template.html.twig
![Page 50: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/50.jpg)
AssetsAssetic
Separate tools (non-PHP based)
![Page 51: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/51.jpg)
SecuritySo very hard
Documented in many different ways
It's really good though
Simplified at code level now
![Page 52: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/52.jpg)
Symfony is an early adopter
PHP-FIG
PSR-0, PSR-1, PSR-2, PSR-3, PSR-7 - very quickly adopted
![Page 53: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/53.jpg)
Extensive documentation
High quality
Friendly
Good-looking
Well maintained
![Page 54: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/54.jpg)
"The Book"?
![Page 55: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/55.jpg)
Excellent BC promise
@api
![Page 56: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/56.jpg)
A Year With Symfony
![Page 57: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/57.jpg)
Struggling with framework coupling
![Page 58: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/58.jpg)
The fight against CRUD
![Page 59: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/59.jpg)
Hexagonal architecture
![Page 60: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/60.jpg)
![Page 61: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/61.jpg)
phparchitecturetour.com
![Page 62: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/62.jpg)
Conclusion
![Page 63: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/63.jpg)
Symfony - The biggest change
Dependency injection (container)
Which is an enabler for better code
Because: maintainable and testable
![Page 64: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/64.jpg)
My personal development:
1. I love symfony
2. I love Symfony2
3. I want to decouple from it
4. I want to fully embrace it whenever that's okay
![Page 65: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/65.jpg)
For me it's about
Knowing your framework
Being fast with it
Not being totally dependent on it
![Page 66: How Symfony Changed My Life](https://reader035.vdocuments.net/reader035/viewer/2022062503/58f28c541a28ab41308b4567/html5/thumbnails/66.jpg)
Long live PolderPHP!