Starting with Symfony2

37
Starting with

description

 

Transcript of Starting with Symfony2

Page 1: Starting with Symfony2

Starting with

Page 2: Starting with Symfony2

@zenstruck

About Me

● Kevin Bond● Kitchener, Ontario● PHP Developer

– Symfony2 core/docs contributor

[email protected]

Page 3: Starting with Symfony2

@zenstruck

What is Symfony2?

Page 4: Starting with Symfony2

@zenstruck

What is Symfony2?

● Set of stand-alone, decoupled components

Page 5: Starting with Symfony2

@zenstruck

What is Symfony2?

● Set of stand-alone, decoupled components● Full-stack framework based on these

components

Page 6: Starting with Symfony2

@zenstruck

What is Symfony2?

● Set of stand-alone, decoupled components● Full-stack framework based on these

components● Community

● Forum/Mailing List/IRC (#symfony on Freenode)● 3rd party bundles (knpbundles.com)● 5000+ watchers / 1300+ forks● 560+ unique contributors

Page 7: Starting with Symfony2

@zenstruck

Symfony2 Components

DependencyInjection

EventDispatcher

HttpFoundation

DomCrawler

ClassLoader

CssSelector

HttpKernel

BrowserKit

Templating

Translation

Serializer

Validator

Security

Routing

Console

Process

Config

Finder

Locale

Yaml

Form

Page 8: Starting with Symfony2

@zenstruck

Projects using Symfony2

● Assetic (Process)● Doctrine2 (Console)● PHPUnit (Yaml)● Behat● Silex● Drupal 8● Propel

Page 9: Starting with Symfony2

@zenstruck

Why use Symfony2?

● Fast● PHP 5.3● Well engineered (no singletons)● Forces* best practices● Extensible and flexible● Stable and established● Testable

Page 10: Starting with Symfony2

@zenstruck

What Symfony2 is not

Page 11: Starting with Symfony2

@zenstruck

What Symfony2 is not

MVC Framework

Page 12: Starting with Symfony2

@zenstruck

What Symfony2 is not

MVC Framework

Page 13: Starting with Symfony2

@zenstruck

HTTP Framework

Request Response

Page 14: Starting with Symfony2

@zenstruck

HTTP Framework

Request Response

I don't like MVC because that's not how the web works. Symfony2 is an HTTP framework; it is a Request/Response framework. That's the big deal. The fundamental principles of Symfony2 are centered around the HTTP specification. - Fabien Potencier

Page 15: Starting with Symfony2

@zenstruck

Bundles

● Everything is a bundle (even the framework is a collection of core bundles)

● Bundles contain:● Configuration/Translations/Documentation● Routes/Controllers/Views● Public resources (js/css/images)● Services/Events/Models/Forms etc (* don't make your bundle a library)● Tests● NOT VENDOR LIBS

● Override with child bundle● 690+ bundles on knpbundles.com

Page 16: Starting with Symfony2

@zenstruck

Useful Bundles

● FOSUserBundle● FOSFacebookBundle● KnpMenuBundle● SonataAdminBundle● FOSJsRoutingBundle● OAuthBundle● JMSI18nRoutingBundle

Page 17: Starting with Symfony2

@zenstruck

Anatomy of a Request

Page 18: Starting with Symfony2

@zenstruck

Anatomy of a Request

● Request

Page 19: Starting with Symfony2

@zenstruck

Anatomy of a Request

● Request● Kernel

Page 20: Starting with Symfony2

@zenstruck

Anatomy of a Request

● Request● Kernel

● Controller

Page 21: Starting with Symfony2

@zenstruck

Anatomy of a Request

● Request● Kernel

● Controller

● Response (html, json, xml, etc...)

Page 22: Starting with Symfony2

@zenstruck

Anatomy of a Request

● Request● Kernel

● Controller● Exception?

● Response (html, json, xml, etc...)

Page 23: Starting with Symfony2

Service Container

Page 24: Starting with Symfony2

@zenstruck

Get Started

curl -s http://getcomposer.org/installer | php

composer.phar create-project symfony/framework-standard-edition path/to/install

Page 25: Starting with Symfony2

Demo

Page 26: Starting with Symfony2

@zenstruck

“Killer” Feature

Page 27: Starting with Symfony2

@zenstruck

“Killer” Feature

Symfony2 Reverse Proxy

Page 28: Starting with Symfony2

@zenstruck

3 Types of HTTP Cache

● From the docs:● Browser caches: Every browser comes with its own local cache that

is mainly useful for when you hit "back" or for images and other assets. The browser cache is a private cache as cached resources aren't shared with anyone else.

● Proxy caches: A proxy is a shared cache as many people can be behind a single one. It's usually installed by large corporations and ISPs to reduce latency and network traffic.

● Gateway caches: Like a proxy, it's also a shared cache but on the server side. Installed by network administrators, it makes websites more scalable, reliable and performant.

Page 29: Starting with Symfony2

@zenstruck

Symfony2 Reverse Proxy

● Request● Kernel● Controller● Response (html, json, xml, etc...)

Page 30: Starting with Symfony2

@zenstruck

Symfony2 Reverse Proxy

● Request● Reverse Proxy● Kernel● Controller● Response (html, json, xml, etc...)

Page 31: Starting with Symfony2

@zenstruck

Symfony2 Reverse Proxy

● Request● Reverse Proxy● Kernel● Controller● Response (html, json, xml, etc...)

● Set s-maxage header

Page 32: Starting with Symfony2

@zenstruck

Symfony2 Reverse Proxy

● Request● Reverse Proxy

● Cached version?

● Kernel● Controller● Response (html, json, xml, etc...)

● Set s-maxage header

Page 33: Starting with Symfony2

@zenstruck

Caching Dynamic Content

Page 34: Starting with Symfony2

@zenstruck

Caching Dynamic Content

● Sub-requests

Page 35: Starting with Symfony2

@zenstruck

Caching Dynamic Content

● Sub-requests● ESI – Edge Side Includes

– Server side sub-requests

Page 36: Starting with Symfony2

@zenstruck

Caching Dynamic Content

● Sub-requests● ESI – Edge Side Includes

– Server side sub-requests● CSI – Client Side Includes (new in 2.1)

– Uses javascript (hinclude.js)– Client side sub-requests

Page 37: Starting with Symfony2

@zenstruck

Resources

● github.com/kbond/gpug-symfony2● symfony.com (docs/cookbook)● fabien.potencier.org● knpbundles.com● richardmiller.co.uk● knpuniversity.com● connect.sensiolabs.com● live.symfony.com● mnot.github.com/hinclude