Symfony 2.0 Intro

41
Dustin Whittle - @dustinwhittle

description

A tech talk on Symfony 2.0 for San Francisco PHP/Symfony Meetup at CBS Interactive.

Transcript of Symfony 2.0 Intro

Page 1: Symfony 2.0 Intro

Dustin Whittle - @dustinwhittle

Page 2: Symfony 2.0 Intro

Symfony-Reloaded.org

Page 3: Symfony 2.0 Intro
Page 4: Symfony 2.0 Intro

What is Symfony?Symfony is a PHP 5.3 full-stack web framework. It is written with speed and flexibility in mind. It allows developers to build better and easier to maintain websites with PHP.

Page 5: Symfony 2.0 Intro

What is new in Symfony?

Page 6: Symfony 2.0 Intro

Everything!

Page 7: Symfony 2.0 Intro

It is Symfony not symfony

Page 8: Symfony 2.0 Intro

A fresh look at Symfony

Symfony2 is a complete rewrite of symfony 1.x

Fabien Potencier has been working on Symfony2 for years - almost as long as symfony 1.x

Focus is on Performance, Flexibility, and Extensibility

Cleaner implementations with less magic

Page 9: Symfony 2.0 Intro

Coming from symfony 1.x

If you are launching today, use symfony 1.4

No simple upgrade path to Symfony 2.0

If you are launching in six months use Symfony 2.0

Current release is alpha

Page 10: Symfony 2.0 Intro

The Foundation

PHP 5.3.2+ required

Leverage the latest features for a clean and simple API

Building on the shoulders of giants

ORM: Doctrine2 or Propel

Email: SwiftMailer

Testing: PHPUnit

Logging: Zend Framework

Page 11: Symfony 2.0 Intro

The Core

The Kernel

Bootstraps configuration + loads bundles

The Bundles

Almost all functionality is a bundle in Symfony2

FoundationBundle, DoctrineBundle, DoctrineMongoDBBundle, PropelBundle, SwiftmailerBundle, TwigBundle, ZendBundle

Use bundles to share features between projects

Page 12: Symfony 2.0 Intro

The Core

Dependency Injection Container

Configure dependencies in YAML or XML

Only use what you need when you need it

The Request Handler

Converts a request into a response

Can be highly optimized depending on requirements

Event Dispatcher

Page 13: Symfony 2.0 Intro
Page 14: Symfony 2.0 Intro

Take the quick tour

Page 15: Symfony 2.0 Intro

symfony-reloaded.org/learn

Page 16: Symfony 2.0 Intro

Getting started

Download the sandbox

http://github.com/symfony/symfony-sandbox

Page 17: Symfony 2.0 Intro
Page 18: Symfony 2.0 Intro
Page 19: Symfony 2.0 Intro
Page 20: Symfony 2.0 Intro
Page 21: Symfony 2.0 Intro
Page 22: Symfony 2.0 Intro
Page 23: Symfony 2.0 Intro

Doctrine 2.0

Doctrine2 features fully integrated

Database Abstraction Layer

Object Relational Mapper

Rewritten from scratch to focus on performance

Less magic

Page 24: Symfony 2.0 Intro

Configuring Doctrine DBAL

doctrine.dbal: default_connection: default connections: default: driver: PDOSqlite dbname: Symfony user: root password: null host: localhost port: ~ path: %kernel.data_dir%/symfony.sqlite event_manager_class: Doctrine\Common\EventManager configuration_class: Doctrine\DBAL\Configuration wrapper_class: ~ options: []

Page 25: Symfony 2.0 Intro

Using Doctrine Connections

class MyController extends DoctrineController{ public function indexAction() { $conn = $this->getDatabaseConnection('default'); // ... }}

Page 26: Symfony 2.0 Intro

Configuring Doctrine ORM

doctrine.orm: default_entity_manager: default cache_driver: apc # array, apc, memcache, xcache entity_managers: default: connection: default

Page 27: Symfony 2.0 Intro

Creating Doctrine Entities/** @Entity */class User{ /** * @Id @Column(type="integer") * @GeneratedValue */ private $id;

/** @Column(type="string", length=255) */ private $name;

public function getId() { return $this->id; }

public function getName() { return $this->name; }

public function setName($name) { $this->name = $name; }}

Page 28: Symfony 2.0 Intro

Using Doctrine Entities

class MyController extends DoctrineController{ public function indexAction() { $em = $this->getEntityManager(); $query = $em->createQuery('select u from MyBundle:User u');

$users = $query->execute(); // ... }}

Page 29: Symfony 2.0 Intro

Using Doctrine Entities

class MyController extends DoctrineController{ public function indexAction() { $em = $this->getEntityManager(); $qb = $em->createQueryBuilder() ->select('u') ->from('MyBundle:User', 'u');

$query = $qb->getQuery(); $users = $query->execute(); // ... }}

Page 30: Symfony 2.0 Intro

Console commands implemented for improved developer workflow:

Ensure production settings

Clear metadata, query and result cache

Load data fixtures

Create and drop configured databases

Generate entities from mapping information

Generate new skeleton entities

Generate skeleton entity repository classes

Convert mapping information between formats

Page 31: Symfony 2.0 Intro

Doctrine 2.0 & MongoDB

Doctrine 2.0 supports Mongodb

MongoDB Object Document Mapper

Transparent persistence to MongoDB

Same architecture as ORM

Map a class as an entity and document

Page 32: Symfony 2.0 Intro

Configure Doctrine ODM

doctrine_odm.mongodb: default_document_manager: default cache_driver: array document_managers: default: connection: mongodb connections: mongodb: server: localhost/somedatabase

Page 33: Symfony 2.0 Intro

Mongo Documents

/** @Document */class User{ /** * @Id */ private $id;

/** @String */ private $name;

public function getId() { return $this->id; }

public function getName() { return $this->name; }

public function setName($name) { $this->name = $name; }}

Page 34: Symfony 2.0 Intro

Using Doctrine/MongoDB

class MyController extends DoctrineController{ public function createAction() { $dm = $this->getDocumentManager(); $user = new User(); $user->setName('Jonathan H. Wage'); $dm->persist($user); $dm->flush(); // ... }}

Page 35: Symfony 2.0 Intro

Using Doctrine/MongoDB

class MyController extends DoctrineController{ public function indexAction() { $dm = $this->getDocumentManager(); $query = $dm->createQuery('User') ->where('username', 'jwage');

$user = $query->getSingleResult(); // ... }}

Page 36: Symfony 2.0 Intro

Symfony 2.0 Forms

Page 37: Symfony 2.0 Intro

Symfony 2.0 Testing

Uses PHPUnit 3.5.x

Adds custom web client + crawler

Page 38: Symfony 2.0 Intro

Symfony 2.0 Caching

Leverages ESI for ideal caching on the edge

Easy integration with any reverse proxy cache

Page 39: Symfony 2.0 Intro

Finding Documentation

Symfony Official Site

http://symfony-reloaded.org

The State of Symfony slides

http://www.slideshare.net/fabpot

Join the [email protected]

Page 40: Symfony 2.0 Intro

Want to contribute?

http://github.com/symfony/symfony

Page 41: Symfony 2.0 Intro