Download - Starting with Symfony2
Starting with
@zenstruck
About Me
● Kevin Bond● Kitchener, Ontario● PHP Developer
– Symfony2 core/docs contributor
@zenstruck
What is Symfony2?
@zenstruck
What is Symfony2?
● Set of stand-alone, decoupled components
@zenstruck
What is Symfony2?
● Set of stand-alone, decoupled components● Full-stack framework based on these
components
@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
@zenstruck
Symfony2 Components
DependencyInjection
EventDispatcher
HttpFoundation
DomCrawler
ClassLoader
CssSelector
HttpKernel
BrowserKit
Templating
Translation
Serializer
Validator
Security
Routing
Console
Process
Config
Finder
Locale
Yaml
Form
@zenstruck
Projects using Symfony2
● Assetic (Process)● Doctrine2 (Console)● PHPUnit (Yaml)● Behat● Silex● Drupal 8● Propel
@zenstruck
Why use Symfony2?
● Fast● PHP 5.3● Well engineered (no singletons)● Forces* best practices● Extensible and flexible● Stable and established● Testable
@zenstruck
What Symfony2 is not
@zenstruck
What Symfony2 is not
MVC Framework
@zenstruck
What Symfony2 is not
MVC Framework
@zenstruck
HTTP Framework
Request Response
@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
@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
@zenstruck
Useful Bundles
● FOSUserBundle● FOSFacebookBundle● KnpMenuBundle● SonataAdminBundle● FOSJsRoutingBundle● OAuthBundle● JMSI18nRoutingBundle
@zenstruck
Anatomy of a Request
@zenstruck
Anatomy of a Request
● Request
@zenstruck
Anatomy of a Request
● Request● Kernel
@zenstruck
Anatomy of a Request
● Request● Kernel
● Controller
@zenstruck
Anatomy of a Request
● Request● Kernel
● Controller
● Response (html, json, xml, etc...)
@zenstruck
Anatomy of a Request
● Request● Kernel
● Controller● Exception?
● Response (html, json, xml, etc...)
Service Container
@zenstruck
Get Started
curl -s http://getcomposer.org/installer | php
composer.phar create-project symfony/framework-standard-edition path/to/install
Demo
@zenstruck
“Killer” Feature
@zenstruck
“Killer” Feature
Symfony2 Reverse Proxy
@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.
@zenstruck
Symfony2 Reverse Proxy
● Request● Kernel● Controller● Response (html, json, xml, etc...)
@zenstruck
Symfony2 Reverse Proxy
● Request● Reverse Proxy● Kernel● Controller● Response (html, json, xml, etc...)
@zenstruck
Symfony2 Reverse Proxy
● Request● Reverse Proxy● Kernel● Controller● Response (html, json, xml, etc...)
● Set s-maxage header
@zenstruck
Symfony2 Reverse Proxy
● Request● Reverse Proxy
● Cached version?
● Kernel● Controller● Response (html, json, xml, etc...)
● Set s-maxage header
@zenstruck
Caching Dynamic Content
@zenstruck
Caching Dynamic Content
● Sub-requests
@zenstruck
Caching Dynamic Content
● Sub-requests● ESI – Edge Side Includes
– Server side sub-requests
@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
@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