Symfony 2.0 Intro
-
Upload
dustin-whittle -
Category
Technology
-
view
7.130 -
download
1
description
Transcript of Symfony 2.0 Intro
![Page 1: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/1.jpg)
Dustin Whittle - @dustinwhittle
![Page 2: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/2.jpg)
Symfony-Reloaded.org
![Page 3: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/3.jpg)
![Page 4: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/5.jpg)
What is new in Symfony?
![Page 6: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/6.jpg)
Everything!
![Page 7: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/7.jpg)
It is Symfony not symfony
![Page 8: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/13.jpg)
![Page 14: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/14.jpg)
Take the quick tour
![Page 15: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/15.jpg)
symfony-reloaded.org/learn
![Page 16: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/16.jpg)
Getting started
Download the sandbox
http://github.com/symfony/symfony-sandbox
![Page 17: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/17.jpg)
![Page 18: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/18.jpg)
![Page 19: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/19.jpg)
![Page 20: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/20.jpg)
![Page 21: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/21.jpg)
![Page 22: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/22.jpg)
![Page 23: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/23.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/24.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/25.jpg)
Using Doctrine Connections
class MyController extends DoctrineController{ public function indexAction() { $conn = $this->getDatabaseConnection('default'); // ... }}
![Page 26: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/26.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/27.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/28.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/29.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/30.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/31.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/32.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/33.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/34.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/35.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/36.jpg)
Symfony 2.0 Forms
![Page 37: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/37.jpg)
Symfony 2.0 Testing
Uses PHPUnit 3.5.x
Adds custom web client + crawler
![Page 38: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/38.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/39.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/40.jpg)
Want to contribute?
http://github.com/symfony/symfony
![Page 41: Symfony 2.0 Intro](https://reader034.fdocuments.in/reader034/viewer/2022052310/554a4f81b4c905522f8b479d/html5/thumbnails/41.jpg)