how symfony changed my life

66
Matthias Noback Lelystad, September 1 st 2015 10 years! How Symfony changed my life

Upload: matthiasnoback

Post on 16-Apr-2017

2.070 views

Category:

Software


1 download

TRANSCRIPT

Page 1: How Symfony Changed My Life

Matthias Noback Lelystad, September 1st 2015

10

years!

How Symfony changed my life

Page 2: How Symfony Changed My Life

Pre-symfony

Page 3: How Symfony Changed My Life

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

From include('script.php')

To proper function calls

Page 5: How Symfony Changed My Life

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

From PHP & HTML in the same file

To PHP classes and Smarty template files

Page 7: How Symfony Changed My Life

From copying snippets from the Internet

To downloading single-purpose libraries

Page 8: How Symfony Changed My Life

Feeling mighty fine

SQL injection

Register globals

Session hijacking

Magic quotes

CSRF

XSS

Page 9: How Symfony Changed My Life

Basically...

Page 10: How Symfony Changed My Life

But... performance was very good ;)

Page 11: How Symfony Changed My Life

Driebit (2008)

Page 12: How Symfony Changed My Life

symfony (1)with a lower-case s

Page 13: How Symfony Changed My Life

Symfony Camp (2007)

Stefan Koopmanschap

Page 14: How Symfony Changed My Life

The Book (back then)

François Zaninotto(Propel)

symfony 1.1

Page 15: How Symfony Changed My Life

Working with symfony 1 meant...

MVC

Fat controllers

Fat models

(Zend devs wrote fat services as well)

Page 16: How Symfony Changed My Life

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

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

God object

sfContext::getInstance()

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

Page 19: How Symfony Changed My Life

Just reach out

Page 20: How Symfony Changed My Life

Why bad?

Testability

Isolation

Side-effects

Configuration

No separation of concerns

Page 21: How Symfony Changed My Life

CTO at SensioLabs DE

Page 22: How Symfony Changed My Life

Pushing the limits

Page 23: How Symfony Changed My Life

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

Switch to Doctrine

It was... new

version 1.0

Page 25: How Symfony Changed My Life

Develop some Plugins

Page 26: How Symfony Changed My Life

Learn about advanced topics

Emails

Forms

Doctrine

Internals

Page 27: How Symfony Changed My Life

SymfonyLive Paris 2010

Revealing Symfony2

Page 28: How Symfony Changed My Life

SymfonyLive Paris 2011

Almost releasing Symfony 2.0

Excitement all over the place

Page 29: How Symfony Changed My Life

Start using 2.0?

No backwards compatibility

No best practices

No CMS

Page 30: How Symfony Changed My Life

Not even...

... an admin

generator

only for scaffolding ;)

Page 31: How Symfony Changed My Life

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

Symfony2

capital "S"

no space, for Google

Page 33: How Symfony Changed My Life

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

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

Dependency injection container

Major improvement: everything can be configured

No runtime resolvers anymore

Page 36: How Symfony Changed My Life

What's dependency injection?

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

$bar)

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

Page 37: How Symfony Changed My Life

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

What does DI give us?

Single responsibility

Testability

Dependency inversion

SpeedFlexibility

Page 39: How Symfony Changed My Life

Active record -> data mapper

Doctrine 1/Propel

Doctrine 2/...

Page 40: How Symfony Changed My Life

Active record sample

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

Page 41: How Symfony Changed My Life

Data mapper sample

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

POPO

Page 42: How Symfony Changed My Life

Why is that better?

Isolation

Model first

Decoupling (not always a good reason)

Page 43: How Symfony Changed My Life

Bundle ~= Plugin

Page 44: How Symfony Changed My Life

First-class citizens

Page 45: How Symfony Changed My Life

A bundle for each feature

Page 46: How Symfony Changed My Life

Framework coupling

Libraries are framework-independent

Bundles are explicitly meant to couple code to the framework

Page 47: How Symfony Changed My Life

Bundles: service definitions

Service definition files

Bundle extension

Bundle configuration

Compiler pass

Page 48: How Symfony Changed My Life

Bundle: root for resources

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

Page 49: How Symfony Changed My Life

Resources

Expose: Templates

Translations ...

Page 50: How Symfony Changed My Life

AssetsAssetic

Separate tools (non-PHP based)

Page 51: How Symfony Changed My Life

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

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

Extensive documentation

High quality

Friendly

Good-looking

Well maintained

Page 54: How Symfony Changed My Life

"The Book"?

Page 55: How Symfony Changed My Life

Excellent BC promise

@api

Page 56: How Symfony Changed My Life

A Year With Symfony

Page 57: How Symfony Changed My Life

Struggling with framework coupling

Page 58: How Symfony Changed My Life

The fight against CRUD

Page 59: How Symfony Changed My Life

Hexagonal architecture

Page 60: How Symfony Changed My Life
Page 61: How Symfony Changed My Life

phparchitecturetour.com

Page 62: How Symfony Changed My Life

Conclusion

Page 63: How Symfony Changed My Life

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

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

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

Long live PolderPHP!