Matthias Noback
Paris, November 19th 2015
10
years!
How Symfony
changed my life
Pre-symfony
From ASP using VBScript
and a MS Access database
To PHP with a MySQL database
"You should
try PHP!"
From
include('script.php')
To proper function calls
From PHP 4 and
one mega Page class
To PHP 5 with proper scoping for
methods and properties, and
autoloading
From PHP & HTML
in the same file
To PHP classes and Smarty template
files
From copying snippets
from the Internet
To downloading single-purpose
libraries
Feeling mighty fine
SQL injection
Register globals
Session
hijacking
Magic quotes
CSRF
XSS
Basically...
But... performance
was very good ;)
Driebit (2008)
symfony (1)
with a lower-case s
Symfony Camp
(2007)
Stefan Koopmanschap
The Book
(back then)
François Zaninotto
(Propel)
symfony 1.1
Working with
symfony 1 meant...
MVC
Fat controllers
Fat models
(Zend devs wrote fat services as well)
Not in the controller
or the model?
Put it in:
A "peer" class
A utility class
Or: create a global singleton for it
What's a singleton?
Static
Global
Single
instance
class Singleton

{

private static $instance;



private function __construct()

{

}



public static function getInstance()

{

if (self::$instance === null) {

self::$instance = new self();

}



return self::$instance;

}

}
God object
sfContext::getInstance()
getUser(), getResponse(),
getRequest(), getLogger(), getI18N(),
...
Just reach out
Why bad?
Testability
Isolation
Side-effects
Configuration
No separation of concerns
CTO at SensioLabs DE
Pushing the limits
Tweaking symfony
Event listeners: add missing
methods on the fly (!)
Filters: chain of responsibility
factories.yml and other config files
Switch to Doctrine
It was... new
version 1.0
Develop some
Plugins
Learn about
advanced topics
Emails
Forms
Doctrine
Internals
SymfonyLive
Paris 2010
Revealing
Symfony2
SymfonyLive
Paris 2011
Almost releasing
Symfony 2.0
Excitement all
over the place
Start using 2.0?
No backwards compatibility
No best practices
No CMS
Not even...
... an
admin
generator
only for scaffolding ;)
Migrating to 2.0?
Company owners didn't dare to take
the step (I agree with them now!)
I left the company :)
Symfony2
capital "S"
no space, for Google
Infrastructure
1. Git for version control
2. Install script or Git
submodules for vendor
code
3. At some point:
composer started
handling dependencies
Templating
Twig:
Own syntax
No PHP code
"Auto-safe"
Fast (the engine that
is)
"Templating engines in PHP" by Fabien Potencier
Dependency
injection container
Major improvement: everything can
be configured
No runtime resolvers anymore
What's dependency
injection?
class Foo

{

private $bar;



public function __construct(Bar $bar)

{

$this->bar = $bar;

}

}
What's a DI
container?
class Container

{

public function createFoo()

{

return new Foo($this->getBar());

}



private function createBar()

{

return new Bar();

}

}
What does DI give
us?
Single responsibility
Testability
Dependency inversion
Speed
Flexibility
Active record ->
data mapper
Doctrine 1/Propel
Doctrine 2/...
Active record
sample
class Invoice extends Record

{

}



$invoice = new Invoice();

$invoice->save();
Data mapper
sample
class Invoice

{

}



$invoice = new Invoice();

$entityManager->persist($invoice);
POPO
Why is that better?
Isolation
Model first
Decoupling (not always a good reason)
Bundle ~= Plugin
First-class citizens
A bundle for each
feature
Framework
coupling
Libraries are framework-
independent
Bundles are explicitly meant to
couple code to the framework
Bundles: service
definitions
Service definition files
Bundle extension
Bundle configuration
Compiler pass
Bundle: root for
resources
@MyBundle/Resources/views/
template.html.twig
Resources
Expose:
Templates
Translations
...
Assets
Assetic
Separate tools (non-PHP based)
Security
So very hard
Documented in many
different ways
It's really good
though
Simplified at code
level now
Symfony is an
early adopter
PHP-FIG
PSR-0, PSR-1, PSR-2, PSR-3, PSR-7 -
very quickly adopted
Extensive
documentation
High quality
Friendly
Good-
looking
Well
maintained
"The Book"?
Excellent BC
promise
@api
A Year With
Symfony
Struggling with
framework coupling
The fight against
CRUD
Hexagonal
architecture
phparchitecturetour.com
Conclusion
Symfony - The
biggest change
Dependency injection (container)
Which is an enabler for better
code
Because: maintainable and
testable
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
For me it's about
Knowing your framework
Being fast with it
Not being totally dependent on it
Long live
SfPot!

How Symfony changed my life (#SfPot, Paris, 19th November 2015)