International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com symfony Simplify your professional web development with PHP Fabien Potencier http://www.symfony-project.com/ http://www.sensiolabs.com/
86
Embed
symfony: Simplify your professional web development with PHP (IPC Frankfurt 2007)
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
symfonySimplify your professional
web development with PHP
Fabien Potencierhttp://www.symfony-project.com/
http://www.sensiolabs.com/
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Sensio• French Web Agency, founded in 1998
– 150 people– 30 people dedicated to Web technologies
Webmarketing
Open SourceTechnologies
(Framework PHP)
WebTechnologies
SENSIOWeb Agency
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Be Happy… or not$ ./symfony test-functional frontend# get /ok 1 - status code is 200not ok 2 - response selector h1 does not match regex /IPC 2007 Conference/1..2 Looks like you failed 1 tests of 2.
$ ./symfony test-functional frontend# get /ok 1 - status code is 200ok 2 - response selector h1 matches regex /IPC 2007 Conference/1..2 Looks like everything went fine.
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Debugging Tools• Web Debug Toolbar
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Debugging Tools• Error messages
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
What’s New in symfony 1.1?• A new task framework• Decoupling
– Remove singletons– Remove dependencies between core classes– New Event Dispatcher system
• Form / Validation framework
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
New Task Framework• Easier to extend the symfony tasks• Task namespaces• Built-in help system• Tasks are decoupled from the CLI
– Can be called from the CLI– … or from your own code… easily
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Task Namespacesgenerate :app Generates a new application (init-app) :batch Generates a new batch (init-batch) :controller Generates a new controller (init-controller) :module Generates a new module (init-module) :project Generates a new project (init-project)
test :all Launches all tests :functional Launches functional tests :unit Launches unit tests
i18n :extract Extracts i18n strings from php files :find Finds non "i18n ready" strings in an application
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Options: --stability (-s) The preferred stability (stable, beta, alpha) --release (-r) The preferred version --channel (-c) The PEAR channel name --install_deps (-d) Whether to force installation of required dependencies
Description: …
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Task HelpDescription: The plugin:install task installs a plugin:
./symfony plugin:install sfGuargPlugin
By default, it installs the latest stable release.
If you want to install a plugin that is not stable yet, use the stability option:
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Task Calls in your Code# Somewhere in your code
$task = new sfCacheClearTask($dispatcher);$task->run();
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
symfony 1.0 Dependencies
CleanupDependencies
sfRequest
sfResponse
sfContext
sfUsersfStorage
sfRouting
sfI18NsfLogger
sfView
singleton dependency
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
symfony 1.1 Dependencies
CleanupDependencies
sfRequestsfResponse
sfContext
sfUser
sfStorage
sfRouting
sfI18N
sfLogger
sfEventDispatcher
sfView
singleton dependency
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfEventDispatcher• Based on Cocoa Notification Center// sfUser$event = new sfEvent($this, 'user.change_culture', array('culture' => $culture));$dispatcher->notify($event);
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfValidatorSchema• Secure by default
– allow_extra_fields (false by default)– filter_extra_fields (true by default)
• If you pass a value with no matching validator, sfValidatorSchemawill throw an error
• If you switch allow_extra_fields to true, then extra fields won’ttrigger an error but will be removed from the cleaned values
• If you also switch filter_extra_fields to false, then extra fields won’tbe removed from the cleaned values
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfValidatorSchemaForEach$choiceValidator = new sfValidatorSchema(array( 'choice' => $v1,));
$choicesValidator = new sfValidatorSchemaForEach($choiceValidator, 3);
$pollValidator = new sfValidatorSchema(array( 'question' => $v1, 'choices' => $choicesValidator,));
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfValidatorSchemaForEach$pollValidator->clean(array( 'question' => 'Do you like symfony?', 'choices' => array( array('choice' => 'Yes'), array('choice' => 'This is the best'), array('choice' => 'A lot'), ),));
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Validators as Strings$postValidator = new sfValidatorOr(array( new sfValidatorSchemaFilter('age', new sfValidatorInteger(array('min' => 18))), new sfValidatorAll(array( new sfValidatorSchemaFilter('age', new sfValidatorInteger(array('max' => 18))), new sfValidatorSchemaFilter('is_young', new sfValidatorBoolean(array('required' => true))), )),));
$string = $postValidator->asString();' age:Integer({min: 18}) or age:Integer({max: 18}) and is_young:Boolean({required: true})'
$postValidator = new sfValidatorFromDescription($string);
$postValidator->asPhp();
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
$form->bind($input);if ($form->isValid()){ // do something with the cleaned values $form->getValues();}else{ // do something with the errors $form->getErrorSchema();}
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfForm• sfForm can take default values
$form = new AuthorForm(array('first_name' => 'Fabien'));
• sfFormField objects are widgets bound to theinput or default values
echo $form->getFormField('first_name')->render();
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Forms: In a symfony Actionclass bookActions extends sfActions{ public function executeEdit($request) { $this->form = new AuthorForm();
if ($request->isMethod('post')) { $this->form->bind($request->getParameter('book')); if ($this->form->isValid()) { $values = $this->form->getValues();
$this->redirect('@homepage'); } } }}
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfFormPropel• Generated forms for Propel objects• Fully customizable• Introspects the Propel schema
– Maps Propel/Creole types to symfony validators andwidgets
– Foreign keys– Many to many relationships– Internationalized tables
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
sfFormPropelclass bookActions extends sfActions{ public function executeEdit($request) { $this->book = BookPeer::retrieveByPk($request->getParameter('id')); $this->form = new AuthorForm($this->book);
if ($request->isMethod('post')) { $this->form->bind($request->getParameter('book'); if ($this->form->isValid()) { $book = $this->form->save();
$this->validatorSchema['foo'] = new sfValidatorPass(); $this->widgetSchema['foo'] = new sfWidgetIdentity();
$this->setDefault('published_on', time()); }}
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
A Professional Web Framework
• Built from experience• 1.0 stable, maintained with commercial support• Growing community
– Developers in more than 80 countries– 200 000 visitors per month on symfony-project.com– 200 plugins in just 8 months
• Open-Source Documentation– The book (450 pages - GFDL)– Askeet Tutorial (250 pages)
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Yahoo! uses symfony• Yahoo! Bookmarks
– 20 millions users– Web 2.0 / AJAX
• del.icio.us– New beta on symfony– preview.delicious.com
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Next symfony Workshops
En français : Paris, France - Dec 05, 2007
In English : Paris, France - Feb 13, 2008
More info on www.sensiolabs.com
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com
Join Us• Sensio Labs is recruiting in France
– project managers– web developers
• You have a passion for the web?– Web Developer : You have a minimum of 3 years experience in
web development with Open-Source projects and you wish toparticipate to development of Web 2.0 sites using the bestframeworks available.
– Project Manager : You have more than 5 years experience as adeveloper and/or a project manager and you want to managecomplex Web projects for prestigious clients.
International PHP 2007 Conference www.symfony-project.com [email protected] www.sensiolabs.com