symfony_from_scratch
- 4. Why
symfony?
• Agile
Development
– Built
on
best
practices
using
proven
design
patterns
– Built
to
factor
out
common
patterns
and
allow
developers
to
focus
on
application
logic
– Automates
the
tedious
tasks
most
developers
face
daily
• Performance
/
Stability
– Proven
to
scale
on
very
active
web
sites
‐
Y!
/
Sensio
– Tested
code
base
(8000+
unit
and
functional
test)
• Maintainability
– Provides
reusable
structures
(DRY)
– Enforces
consistency
amongst
developers
• Support
– Great
documentation
and
very
active
community
- 5. How
is
symfony
different?
• symfony
is
not
a
component
library
like
eZ
Components
or
Zend
Framework
• Adopt
best
ideas
from
anywhere,
using
existing
code
if
available
(prado,
rails,
django)
• It
is
a
full‐stack
framework
for
building
complex
web
applications
– When
you
create
a
symfony
project,
you
have
all
of
the
tools
you
need
to
get
started.
– It
is
not
targeted
for
building
simple
applications
– No
assembly
required
• A
flexible
and
pluggable
architecture
- 6. Clean
Design
• Built
using
proven
design
patterns
– Model‐View‐Controller
• Separation
of
data
access,
presentation
logic,
and
business
logic
– Factories
for
customization
• Built
to
embrace
agile
development
principles
– Allows
developers
to
easily
follow
• Extreme
Programming
/
Test
Driven
Development
• DRY
(Don’t
Repeat
Yourself)
- 10. symfony
cli
• symfony
cli
– Provides
project
management
tasks
for
• Creation
of
projects,
applications,
and
modules
• Configuring
database
+
project
settings
• Installing
and
Removing
plugins
• Managing
model
(regenerating
om
+
loading
fixtures)
• Executing
Unit
+
Functional
Tests
• Deploying
project
to
production
• Rotating
and
purging
logs
– Foundation
for
cli
applications
and
custom
tasks
- 13. Debug
Environment
• Web
Debug
Toolbar
– Browser
access
to
relevant
information
• Request
Parameters
/
Sessions
/
Cookies
• Configuration
(symfony/php)
– Logs
&
Debug
Messages
• xDebug
Integration
(Execution
Traces)
– SQL
Query
Monitor
• Raw
SQL
+
Query
Time
– Performance
Monitor
• Memory
Consumption
• Timers
– Cache
Monitor
– Logging
- 14. Routing
System
• Front
Web
Controller
dispatches
request
to
appropriate
controller
based
on
route
• Routing
based
on
path
info
or
patterns
– Pattern
routing
supports
regex
requirements
• A
maintainable
mod_rewrite
with
helpers
blog_permalink:
url:
/blog/:permalink
param:
{
module:
blog,
action:
show
}
requirements:
{
permalink:
.*
}
- 15. The
Controller
Layer
• Contains
all
business
logic
• Based
on
modules
and
actions
• Actions
are
controllers
• Modules
are
a
collection
of
related
actions
– User
=
login/logout/register/profile
• Modules
are
represented
by
a
directory
structure
(config,
lib,
templates)
and
a
class
(actions.class.php/components.class.php)
• Actions
can
share
settings
(view,
cache,
security)
• Actions
return
views
(Success,
Error,
Custom)
- 17. The
Model
Layer
– ORM:
Propel
or
Doctrine
– Default
is
Propel
(so
that
is
what
we
will
discuss)
• Not
exactly
ActiveRecord
=
Row
Data
Gateway
+
Table
Data
Gateway
Implementation
– Clean
separation
of
table
operation
objects
and
row
instances
– “Object”
classes
for
rows
(RDG)
– “Peer”
classes
for
table
operations
(TDG)
• Database
abstraction
via
Creole
library
• Code
+
DDL
Builder
+
tasks
built
on
Phing
– Customizable
Builders
• Reusable
behaviors:
(Act
As,
Paranoid
Delete,
updated_at,
created_by)
- 19. Model
‐
Schema
propel:
posts:
_attributes:
{
phpName:
Post
}
id:
{
type:
integer,
required:
true,
primaryKey:
true,
autoIncrement:
true
}
title:
varchar(255)
excerpt:
longvarchar
body:
longvarchar
created_at:
~
comments:
_attributes:
{
phpName:
Comment
}
id:
{
type:
integer,
required:
true,
primaryKey:
true,
autoIncrement:
true
}
post_id:
{
type:
integer,
primaryKey:
true,
foreignTable:
posts,
foreignReference:
id,
ondelete:
cascade
}
author:
varchar(255)
email:
varchar(255)
body:
longvarchar
created_at:
~
- 21. The
View
Layer
• PHP
as
a
template
language
– No
smarty
layer,
instead
we
have
helpers
– Helpers
are
template
functions
(think:
rails)
– I18N,
Date,
Text,
Cache,
Routing
• View
configuration
managed
via
view.yml
– Meta
tags,
title,
javascript,
css,
layout,
component
slots
• Layout
• Partials
+
Slots
– Template
fragment
without
business
logic
• Components
– Template
fragment
with
business
logic
• Component
Slots
– Slot
in
layout
for
contextual
content
- 25. Easy
rich
interactions
in
PHP
• Template
Helpers
inspired
from
Rails
– Based
on
prototype/script.aculo.us
• Easy
implementations
in
one
line
of
php
– AJAX
Interactions
‐>
link_to_remote
– Visual
Effects
‐>
visual_effect
– Auto
Complete
‐>
input_autocomplete_tag
– Inline
Editing
‐>
input_inline_editor_tag
– Drag
and
Drop
‐>
draggable_element
– Rich
Text
Editing
‐>
textarea_tag
w/
rich=tinymce|fck
– Rich
Calendar
‐>
input_date_tag
- 26. The
Caching
System
• Powerful
view
cache
layer
with
many
adapters:
file
based,
sqlite,
memcache,
apc,
xcache,
eaccelerator
• Can
bind
cache
to
anything
(user/culture/id)
• Components/Partials
can
be
cached
individually
• Actions
can
be
cached
with
or
without
layout
• View
cache
manager
provides
great
interface
to
selectively
invalidate
based
on
url
pattern
• sfSuperCache
can
provide
full
page
caching
(skipping
php
process)
• HTTP
1.1
Cache
Header
Management
- 29. I18n
&
L10n
• Inspired
by
PRADO
• Flexible
Configuration
– Dictionaries
can
be
XLIFF,
gettext,
or
database
• Caching
• Template
Helpers
– Dealing
with
text
=
__()
• Works
with
complex
strings,
enforces
separation
– Easy
date,
time,
currency
formatting
• Interface
and
Data
Localization
– Support
for
internationalization
in
database
tables
- 30. The
Plugin
System
• Plugins
are
packages
– Configuration,
Object
Model,
Libraries,
Helpers,
Modules,
Tasks,
Tests,
Assets
• Easy
to
install
via
PEAR
– symfony
plugin‐install
or
pear
install
• Plugins
can
be
overridden/extended
– Configuration,
Object
Model,
Actions,
Templates
- 31. symfony
Applications
• Askeet
‐
trac.askeet.com
– Question
and
Answer
site/tutorial
• Demo
‐
Askeet.com
• Tutorial
‐
symfony‐project.com/askeet
• Snipeet
‐
trac.snipeet.com
– Snippet
repository
• Demo
‐
symfony‐project.com/snippets
• Motilee
‐
trac.motilee.com
– Forum
System
• Demo
–
motilee.com
• SteerCMS
‐
steercms‐project.org
– Content
Management
System
• Symfonians
‐
symfonians.net
– Social
Network
+
Community
Showcase
• Bartertown
–
sourceforge.net/projects/bartertown
– Auction
System
- 32. symfony
Plugins
• ORM
– sfPropelPlugin,
sfDoctrinePlugin
• Javascript
Framework
Integration
– sfUJSPlugin,
sfJqueryPlugin,
sfYUIPlugin,
sfExtPlugin,
sfDojoPlugin
• Third
Party
Library
Integration
– sfZendPlugin,
sfSwiftMailer,
sfJpgraphPlugin,
sfChartdirectorPlugin
• Application
Functionality
– sfSimpleCMSPlugin,
sfSimpleBlogPlugin,
sfSimpleForumPlugin,
sfSimpleNewsPlugin,
sfMediaLibraryPlugin
• User
Authentication
– sfGuardPlugin,
sfOpenIDPlugin
• Ecommerce
– sfShoppingCartPlugin,
sfAuthorizeNetPlugin,
sfQuickbooksExportPlugin
- 34. A
quick
example
application
• Building
a
feed
aggregator
– Frontend
• Login
/
Logout
/
Register
/
Profile
• Display
feeds
individually
by
name
• Aggregate
feeds
and
create
aggregate
RSS
feed
– Administration
• Manage
feed
categories
+
feeds
• Manage
users,
groups,
and
permissions
- 35. Installation
• PEAR
– pear
channel‐discover
pear.symfony‐project.com
– pear
install
symfony/symfony
• Subversion
(svn:externals)
– svn
export
http://svn.symfony‐project.com/branches/1.1
symfony
- 42. Integrate
the
Zend
framework
• Download
Zend
and
install
in
lib/vendor/zf
• Chain
Zend
Autoloading
class
frontendConfiguration
extends
sfApplicationConfiguration
{
/**
*
Initializes
the
current
configuration.
*/
public
function
initialize()
{
parent::initialize();
set_include_path($sf_zend_lib_dir.PATH_SEPARATOR.get_include_path());
require_once($sf_zend_lib_dir.’/Zend/Loader.php');
spl_autoload_register(array('Zend_Loader',
'loadClass'));
}
}
- 57. Documentation
• The
Definitive
Guide
to
symfony
– http://symfony‐project.com/book/trunk
– Released
open
source
1/29/2007
– Licensed
under
GFDL
• API
Documentation
– Good
coverage
• Wiki
– Many
useful
guides
and
how
to
– Many
user
contributed
tips
- 58. Askeet
Advent
• Askeet.com
– http://symfony‐project.com/askeet
• 24
Day
Tutorial
on
• How
to
build
a
real
web
2.0
application
• In‐depth
coverage
of
all
aspects
of
symfony
- 60. Example
Code
• Askeet
– http://trac.askeet.com
• Snippets
– http://symfony‐project.com/snippets/
• Snipeet
– http://trac.snipeet.com
- 61. Finding
Help
•
Forums
– http://www.symfony‐project.com/forum
• IRC
– irc.freenode.net/#symfony
• Mailing
List
(Google
Groups)
– symfony‐users@googlegroups.com
– archived
&
searchable
- 62. Real
World
Performance
• Hello
World
in
10‐15ms
– APC
/
Syck
• symfony
can
provide
many
features
– disable
the
ones
you
will
not
use
• Build
intelligently,
cache
effectively
• sfOptimizerPlugin
/
sfSuperCache
• Yahoo!
Bookmarks
/
Y!
Answers
• symfony‐project.com
– digg,
slashdot,
techcrunch,
ajaxian
- 64. Yahoo!
is
hiring
frontend
and
backend
engineers
talk
to
Marcus
Chan
for
more
info.
(so
is
Education.com
and
Current
Media)