simplify your professional web development with symfony
TRANSCRIPT
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
symfonySimplify your professional
web development with PHP
Francois Zaninottohttp://www.symfony-project.com/
http://www.sensio.com/
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Professional
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
ProfessionalHeavyweight, complexVery expensiveFull FeaturedPerformantExtensibleDocumentedSupportedConfigurableStableEasy to use
Java StrutsMicrosoft .Net
Symfony
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
PHP for professionalsStable
PerformantDocumentation
Object-oriented (as of PHP5)Cheap and efficient Hosts
SupportLibraries
Developers for hireEasy
CheapLarge Community
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
PHP for professionalsStable
PerformantDocumentation
Object-oriented (as of PHP5)Cheap and efficient Hosts
SupportLibraries
Developers for hireEasy
CheapLarge Community
Bad reputationSpaghetti codeAmateur codingReinventing the wheelBC breaksInconsistent syntaxBloated
…PHP4
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Develop faster• Each line of code has a cost
– To write the line– To test it– To maintain it
• Write less code– Architecture : controller, ORM, … – Configuration– Autoloading– Generators– Helpers
• More time for business rules, edge cases, …
less code
less complexity
less bugs
more productivity
more time
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Don’t reinvent the wheel• Follow best practices
• Object orientation• MVC Pattern : Model / View / Controller• Object-Relational Mapping / Active Record• Unit and functional tests• Agile development
simplifyyour life
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Professionals need more than PHP alone
a PHP framework?
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Professionals need more than PHP alone
a PHP framework?
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Many of them lack…Tests
StabilitySupportSecurity
ExamplesLiberal licenseDocumentation
Critical user massMulti-platformnessDB engines support
Not suitable for professionals
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
SensioFrench Web AgencyFounded 9 years ago200 web projects30 people Faith in open-sourceDemanding clients
Webmarketing
Open SourceTechnologies
(Framework PHP)
WebTechnologies
SENSIOWeb Agency
Objectives: Have fun
Make money
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
The challenge
Bring together the Enterprise worldand the Open-Source
world
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
symfony• PHP 5 Web Framework• Based on 9 years of Sensio experience• Based on well-known projets (Mojavi, Propel, Prado)
• Open-Source• Built for :
– Professional Websites– Complex needs– Demanding environments
LicenceMIT
Bring togetherEntreprise World
Open-Source World
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
What makes the differenceDocumentationConfigurabilityXSS protectionDebugging toolsFunctional testsExtensibility : PluginsAdmin GeneratorORM : Propel or Doctrinei18n / l10n1.0 maintained for a long time
StandardPHP 5MVC
RoutingCache
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Installation is a breeze• PEAR $ pear channel-discover pear.symfony-project.com $ pear install symfony/symfony-1.0.0
• SVN / symlink $ svn propedit svn:externals symfony http://svn.symfony-project.com/branches/1.0
• Sandbox $ curl -O http://www.symfony-project.com/get/sf_sandbox-1.0.0.tgz $ tar zxpf sf_sandbox-1.0.0.tgz
easy
fast
recommended
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Directory structure generation$ mkdir ~/sfdemo$ cd ~/sfdemo
$ symfony init-project sfdemo$ ./symfony init-app frontend
Project
Application(s)
Module(s)
Action(s)Composant(s)
Template
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Database connection settings
# config/databases.yml prod: propel: param: password: PAssWD all: propel: class: sfPropelDatabase param: dsn: mysql://root:@localhost/sfdemo
Environmentsupport
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Database schema definition
# config/schema.ymlpost: title: { type: varchar, size: 255 } content: { type: longvarchar } is_published: { type: boolean } author_id: { type: integer, foreignTable: author, foreignReference: id } created_at: ~
SQL abstraction
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Test data
# data/fixtures/data.yml Author: fabien: first_name: Fabien last_name: Potencier Post: first_post: author_id: fabien title: Xtech 2007
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Generate the thing
$ ./symfony propel-build-all-load frontend
1) Creates model classes2) Converts schema to SQL3) Creates tables4) Loads test data
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Model// lib/model/Author.phpclass Author extends BaseAuthor{ function getFullName() { return $this->getFirstName().' '.$this->getLastName(); }}
$author = new Author();$author->setFirstName('Fabien');$author->setLastName('Potencier');$author->save();
$post = new Post();$post->setAuthor($author);$post->setPublishedOn('12:00 tomorrow');$post->isPublished(true);$post->save();
$posts = PostPeer::doSelect(new Criteria());
ORMObject Relationship Mapping
Propel / Doctrine
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Backend creationAutomatic creation of an Administration
Backend, ready for production– Lists– Pagination– Sorting
$ ./symfony propel-init-admin frontend post Post
1) Creates a post module2) Generates configuration
Generated code is MVCand customizableConfiguration file
ControllerTemplates
– Filters– Validation– CRUD
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
ConfigurabilityModule level # apps/frontend/modules/post/config/generator.yml generator: class: sfPropelAdminGenerator param: model_class: Post list: display: [=title, author, created_at] filters: [title, author_id, published_on] max_per_page: 5
Application level # apps/frontend/config/security.yml default: is_secure: on credentials: admin
$ ./symfony plugin-install http://plugins.symfony-project.com/sfGuardPlugin
ConfigurationFramework
ProjectApplication
Module
LOC : 0
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Admin Generator – list view
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Admin Generator – edit view
__toString()
widgets m2m relationship
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
ExtensibilityModule extension class postActions extends autoPostActions { protected function addFiltersCriteria($c) { parent::addFiltersCriteria($c); $c->add(PostPeer::IS_PUBLISHED, true); } }
Template customization
Generatedmodule
_edit_* : actions, footer, form, header, messages_list_* : footer, header, messages, td_actions, t(d|h)_stacked, t(d|h)_tabular_filters, editSuccess, listSuccess
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Frontend CreationRouting
<?php echo link_to( $post->getTitle(), '@post?id=’.$post->getId()) ?>
post: param: { module: blog, action: show } requirements: id: \d+ url: /blog/:id.html
<?php echo url_for('@homepage') ?>homepage: param: { module: blog, action: recent } url: /
/blog/1.html
/
homepage: param: { module: blog, action: list } url: /recent: param: { module: blog, action: recent } url: /recent
/
/recent
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Functional TestsSimulate navigation and make smart assertions // test/functional/frontend/blogActionsTest.php $browser = new sfTestBrowser(); $browser->initialize(); $browser-> get('/blog/1.html')-> isStatusCode(200)-> checkResponseElement('h1.title', '/XTech 2007/');
$ ./symfony test-functional frontend# get /ok 1 - status code is 200not ok 2 - response selector h1 does not match regex /XTech 2007/# Looks like you failed 1 tests of 21..2
TDDTest Driven Development
CSS Selector
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Our first line of code# apps/frontend/modules/blog/actions/actions.class.phpclass blogActions extends sfActions{ function executeShow() { $id = $this->getRequestParameter('id'); $this->post = PostPeer::retrieveByPk($id); $this->forward404Unless($this->post); }}
# apps/frontend/modules/post/templates/showSuccess.php<h1 class="title"><?php echo $post->getTitle() ?></h1><h2>par <?php echo $post->getAuthor()->getFullName() ?></h2><p><?php echo $post->getHtmlContent(ESC_RAW) ?></p>
MVCModel / View / Controller
XSSSecure by defaultshortcut
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Debugging tools – The web debug toolbar
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Debugging tools – Meaningful error messages
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Deployment$ ./symfony test-allfunctional/frontend/postActionsTest......................okAll tests successful.Files=1, Tests=2
# config/properties.ini[production] host=1.2.3.4 user=fabien dir=/var/www/sfblog type=rsync
$ ./symfony sync production go
$ ./symfony freeze
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Once it is in productionOptimized for speed and stabilityInternals never shownLogs rotationData dumping404/500 error loggingIncremental updates (via rsync)
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Community PluginsHooks in the symfony code allow for easy extensionNew plugins are created every week
– Doctrine: Full Doctrine ORM support– UJS: Unobtrusive JavaScript– PropelActAsNestedSetBehavior: Nested sets for Propel– PropelActAsTaggableBehavior: Easy tags for Propel– SuperCache: HTML pages cache– ControlPanel: Web management for symfony projects– ErrorLogger: All 404 and 500 logging in a table– Guard: Authentication and authorization features– Feed2: Web feeds management (read&write)– PokaYoke: Client side validation
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
A Professional Web FrameworkBuilt from experienceClean, modular and customizable code1.0 stable, maintained with commercial supportGrowing community
Developpers in more than 80 countries100 000 visitors per month on symfony-project.com
Open-Source DocumentationThe book (450 pages - GFDL)Askeet Tutorial (250 pages)
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
Do you need a second opinion?Yahoo! (USA)
Yahoo! Bookmarks20 millions usersWeb 2.0 / AJAX
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
What’s next?Forge : www.symfony-forge.comNew features for symfony 1.1
– More hooks for plugins– More modularity– Official Doctrine support– Unobstrusive JavaScript support– New form and validation framework
Book translation中文 , Deutsch, Español, Français
Polski, Russian, 日本語 , Italiano, …
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
How to make money with open-source?
Sensio Labs provides symfony-focused servicesTrainingCode auditingConsultingWeb development
If you are looking for a job in France, we're hiring
PHP BootCamp 2007 www.symfony-project.com www.sensio.com
SENSIO S.A.26, rue Salomon de Rothschild
92 286 SURESNES cedexFRANCE
Tél. : +33 1 40 99 80 80Fax : +33 1 40 99 83 34
Contact Francois Zaninotto
http://www.sensio.com/ http://www.symfony-project.com/