how symfony changed my life (#sfpot, paris, 19th november 2015)

68
Matthias Noback Paris, November 19 th 2015 10 years! How Symfony changed my life

Upload: matthiasnoback

Post on 15-Apr-2017

1.597 views

Category:

Software


0 download

TRANSCRIPT

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

Matthias Noback Paris, November 19th 2015

10

years!

How Symfony changed my life

Page 2: How Symfony changed my life (#SfPot, Paris, 19th November 2015)
Page 3: How Symfony changed my life (#SfPot, Paris, 19th November 2015)

Pre-symfony

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

From ASP using VBScript and a MS Access database

To PHP with a MySQL database

"You should try PHP!"

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

From include('script.php')

To proper function calls

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

From PHP 4 and one mega Page class

To PHP 5 with proper scoping for methods and properties, and autoloading

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

From PHP & HTML in the same file

To PHP classes and Smarty template files

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

From copying snippets from the Internet

To downloading single-purpose libraries

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

Feeling mighty fine

SQL injection

Register globals

Session hijacking

Magic quotes

CSRF

XSS

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

Basically...

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

But... performance was very good ;)

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

Driebit (2008)

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

symfony (1)with a lower-case s

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

Symfony Camp (2007)

Stefan Koopmanschap

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

The Book (back then)

François Zaninotto(Propel)

symfony 1.1

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

Working with symfony 1 meant...

MVC

Fat controllers

Fat models

(Zend devs wrote fat services as well)

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

Not in the controller or the model?

Put it in:

A "peer" class

A utility class

Or: create a global singleton for it

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

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 19: How Symfony changed my life (#SfPot, Paris, 19th November 2015)

God object

sfContext::getInstance()

getUser(), getResponse(), getRequest(), getLogger(), getI18N(), ...

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

Just reach out

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

Why bad?

Testability

Isolation

Side-effects

Configuration

No separation of concerns

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

CTO at SensioLabs DE

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

Pushing the limits

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

Tweaking symfony

Event listeners: add missing methods on the fly (!)

Filters: chain of responsibility

factories.yml and other config files

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

Switch to Doctrine

It was... new

version 1.0

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

Develop some Plugins

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

Learn about advanced topics

Emails

Forms

Doctrine

Internals

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

SymfonyLive Paris 2010

Revealing Symfony2

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

SymfonyLive Paris 2011

Almost releasing Symfony 2.0

Excitement all over the place

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

Start using 2.0?

No backwards compatibility

No best practices

No CMS

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

Not even...

... an admin

generator

only for scaffolding ;)

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

Migrating to 2.0?

Company owners didn't dare to take the step (I agree with them now!)

I left the company :)

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

Symfony2

capital "S"

no space, for Google

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

Infrastructure

1. Git for version control

2. Install script or Git submodules for vendor code

3. At some point: composer started handling dependencies

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

TemplatingTwig:

Own syntax

No PHP code

"Auto-safe"

Fast (the engine that is)

"Templating engines in PHP" by Fabien Potencier

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

Dependency injection container

Major improvement: everything can be configured

No runtime resolvers anymore

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

What's dependency injection?

class Foo{ private $bar; public function __construct(Bar

$bar)

{ $this->bar = $bar; }}

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

What's a DI container?

class Container{ public function createFoo() { return new Foo($this->getBar()); } private function createBar() { return new Bar(); }}

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

What does DI give us?

Single responsibility

Testability

Dependency inversion

SpeedFlexibility

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

Active record -> data mapper

Doctrine 1/Propel

Doctrine 2/...

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

Active record sample

class Invoice extends Record{ } $invoice = new Invoice();$invoice->save();

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

Data mapper sample

class Invoice{ } $invoice = new Invoice();$entityManager->persist($invoice);

POPO

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

Why is that better?

Isolation

Model first

Decoupling (not always a good reason)

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

Bundle ~= Plugin

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

First-class citizens

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

A bundle for each feature

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

Framework coupling

Libraries are framework-independent

Bundles are explicitly meant to couple code to the framework

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

Bundles: service definitions

Service definition files

Bundle extension

Bundle configuration

Compiler pass

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

Bundle: root for resources

@MyBundle/Resources/views/template.html.twig

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

Resources

Expose: Templates

Translations ...

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

AssetsAssetic

Separate tools (non-PHP based)

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

SecuritySo very hard

Documented in many different ways

It's really good though

Simplified at code level now

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

Symfony is an early adopter

PHP-FIG

PSR-0, PSR-1, PSR-2, PSR-3, PSR-7 - very quickly adopted

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

Extensive documentation

High quality

Friendly

Good-looking

Well maintained

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

"The Book"?

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

Excellent BC promise

@api

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

A Year With Symfony

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

Struggling with framework coupling

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

The fight against CRUD

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

Hexagonal architecture

Page 61: How Symfony changed my life (#SfPot, Paris, 19th November 2015)
Page 62: How Symfony changed my life (#SfPot, Paris, 19th November 2015)

phparchitecturetour.com

Page 63: How Symfony changed my life (#SfPot, Paris, 19th November 2015)
Page 64: How Symfony changed my life (#SfPot, Paris, 19th November 2015)

Conclusion

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

Symfony - The biggest change

Dependency injection (container)

Which is an enabler for better code

Because: maintainable and testable

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

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 67: How Symfony changed my life (#SfPot, Paris, 19th November 2015)

For me it's about

Knowing your framework

Being fast with it

Not being totally dependent on it

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

Long live SfPot!