SlideShare a Scribd company logo
The new form framework
Bernhard Schussek
What is different in the new form
           framework?
symfony 1.x
          User


         sfForm



        Controller


      Domain Model
symfony 1.x
          User


         sfForm


                     Business Logic
        Controller


      Domain Model
symfony 1.x
          User


         sfForm


                     Business Logic
        Controller


      Domain Model    unit testable!!
symfony 1.x
              User


                                  function configure()
                                  {
                                    unset($this['foo']);
  sfFormDoctrine / sfFormPropel     unset($this['bar']);
                                    unset($this['moo']);
                                    unset($this['comeon!']);
                                    ...




         Domain Model
New architecture
Simplicity and Reusability
Embrace your domain model
Symfony 2
          User


         Form




      Domain Model
Symfony 2
          User
                           Presentation
         Form




      Domain Model         Business Logic



                     designed by you™
Business Logic


class Customer
{

    public $name = 'Default';


    public getGender();

    public setGender($gender);

}
Business Logic                Presentation


class Customer                               Form
{
                                 TextField
    public $name = 'Default';


    public getGender();          ChoiceField
    public setGender($gender);

}
$form = new Form('customer', $customer, ...);

$form->add(new TextField('name'));

$form->add(new ChoiceField('gender', array(
  'choices' => array('male', 'female'),
)));
$form = new Form('customer', $customer, ...);

...

if (isset($_POST['customer']))
{
  $form->bind($_POST['customer']);
}
Business Logic       Presentation




class Customer                     Form
{
            to-one relations    FieldGroup
    public $address;


}
$group = new FieldGroup('address');

$group->add(...);
$group->add(...);
$group->add(...);

$form->add($group);
Business Logic          Presentation

class Customer                        Form
{
                                  CollectionField
              to-many relations    FieldGroup
    public $emails;

                                   FieldGroup



}
$group = new FieldGroup('emails');

$group->add(...);
$group->add(...);

$form->add(new CollectionField($group));
Default                       Localized

  TextField     NumberField                 TimeField

TextareaField   IntegerField            DateTimeField

CheckboxField   PercentField            TimezoneField

 ChoiceField    MoneyField              RepeatedField

PasswordField    DateField              CollectionField

 HiddenField    BirthdayField               FieldGroup

                                             Special
●   Field groups
    —   light-weight subforms
    —   compose other fields or field groups
                                      ?

                     DateField

              ChoiceField                 ChoiceField


    CheckboxField     CheckboxField
Form Rendering
<?php echo $form->renderFormTag('url') ?>

  <?php echo $form->renderErrors() ?>
  <?php echo $form->render() ?>

  <input type="submit" value="Submit" />

</form>
<label for="<?php echo $form['name']->getId() ?>">
  Enter a name
</label>

<?php echo $form['name']->renderErrors() ?>
<?php echo $form['name']->render() ?>
<?php echo $form['date']['day']->render() ?>
<?php echo $form['date']['month']->render() ?>
<?php echo $form['date']['year']->render() ?>
Validation
symfony 1.x
          sfForm
        sfValidator


         Controller


      Domain Model
     Doctrine_Validator
symfony 1.x
          sfForm
        sfValidator


         Controller       Duplicate validation
                                 logic

      Domain Model
     Doctrine_Validator    Failed validation
                           leads to 505 errors
Symfony 2


         Form



      Domain Model
Symfony 2


         Form

                     Validator

      Domain Model
Symfony 2


         Form

                                          Validator

      Domain Model


                                    Validation Metadata

                "how shall the domain model be validated?"
Customer:
  properties:
    name:
      - MinLength: 6
    birthday:
      - Date: ~
    gender:
      - Choice: [male, female]
<class name="Customer">
  <property name="name">
    <constraint name="MinLength">6</constraint>
  </property>
  <property name="birthday">
    <constraint name="Date" />
  </property>
  <property name="gender">
    <constraint name="Choice">
      <value>male</value>
      <value>female</value>
    </constraint>
  </property>
</class>
class Customer
{
  /** @Validation({ @MinLength(6) }) */
  public $name;

    /** @Validation({ @Choice({"male", "female"}) }) */
    public function getGender();

    /** @Validation({ @Valid }) */
    public $gender;
}
Type Check            String       Other

AssertTrue        AssertType   MinLength      Min

AssertFalse            Date    MaxLength     Max

  Blank            DateTime      Regex      Choice

NotBlank               Time       Url        Valid

   Null                          Email     Collection

 NotNull                                      File
●   Constraints can be put on
    —   Classes
    —   Properties
    —   Methods with a "get" or "is" prefix
$validator = $container->getService('validator');

$validator->validate($customer);
Independent from Symfony 2


 Zend    Doctrine 2   Propel
How does all this fit into the form
         framework?
$form = new Form('customer', $customer,
    $this->container->getService('validator'));
$form->bind($_POST['customer']);

if ($form->isValid())
{
  // do something with $customer
}
●   The validation is launched automatically
    upon submission
Common Questions
Q: What if my form does not translate
      1:1 to a domain model?
A: Then the domain model doesn't
            exist yet ;-)
●   Use Case
    —   Extend our form for a checkbox to accept terms
        and conditions
    —   Should not be stored as field in the Customer
        class
class Registration {
  /** @Validation({ @Valid }) */
  public $customer;

    /**
     * @Validation({
     *    @AssertTrue(message="Please accept")
     * })
     */
    public $termsAccepted = false;

    public function process() {
      // save $customer, send emails etc.
    }
}
$form->add(new CheckboxField('termsAccepted'));

$group = new FieldGroup('customer');
$group->add(new TextField('name'));
...

$form->add($group);
if ($form->isValid())
{
  $registration->process();
}
●   The Registration class
    —   can be reused (XML requests, …)
    —   can be unit tested
Q: What if I don't want to validate all
     attributes of an object?
A: Use Constraint groups
●   Use Case
    —   Administrators should be able to create
        Customers with empty names
    —   Normal users not
class Customer
{
  /**
   * @Validation({
   *    @NotBlank(groups="User")
   * })
   */
  public $name;

    ...
}
$validator->validate($customer, 'User');
$form->setValidationGroups('User');
$form->bind($_POST('customer'));

if ($form->isValid())
{
  ...
}
●   Constraint groups can be sequenced
    —   first validate group "Fast"
    —   then, if "Fast" was valid, validate group "Slow"
Questions?

More Related Content

What's hot

Data Validation models
Data Validation modelsData Validation models
Data Validation models
Marcin Czarnecki
 
D8 Form api
D8 Form apiD8 Form api
ZG PHP - Specification
ZG PHP - SpecificationZG PHP - Specification
ZG PHP - Specification
Robert Šorn
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
Michelangelo van Dam
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
Kacper Gunia
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
Javier Eguiluz
 
Sylius and Api Platform The story of integration
Sylius and Api Platform The story of integrationSylius and Api Platform The story of integration
Sylius and Api Platform The story of integration
Łukasz Chruściel
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
Tricode (part of Dept)
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
Javier Eguiluz
 
Business Rules with Brick
Business Rules with BrickBusiness Rules with Brick
Business Rules with Brick
brian d foy
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Kacper Gunia
 
Neo4 J
Neo4 J Neo4 J
Neo4 J
Skills Matter
 
Cloud Entwicklung mit Apex
Cloud Entwicklung mit ApexCloud Entwicklung mit Apex
Cloud Entwicklung mit Apex
Aptly GmbH
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
Ruby on Rails For Java Programmers
Ruby on Rails For Java ProgrammersRuby on Rails For Java Programmers
Ruby on Rails For Java Programmerselliando dias
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
tompunk
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationguest5d87aa6
 

What's hot (17)

Data Validation models
Data Validation modelsData Validation models
Data Validation models
 
D8 Form api
D8 Form apiD8 Form api
D8 Form api
 
ZG PHP - Specification
ZG PHP - SpecificationZG PHP - Specification
ZG PHP - Specification
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Sylius and Api Platform The story of integration
Sylius and Api Platform The story of integrationSylius and Api Platform The story of integration
Sylius and Api Platform The story of integration
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
 
Business Rules with Brick
Business Rules with BrickBusiness Rules with Brick
Business Rules with Brick
 
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
 
Neo4 J
Neo4 J Neo4 J
Neo4 J
 
Cloud Entwicklung mit Apex
Cloud Entwicklung mit ApexCloud Entwicklung mit Apex
Cloud Entwicklung mit Apex
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
Ruby on Rails For Java Programmers
Ruby on Rails For Java ProgrammersRuby on Rails For Java Programmers
Ruby on Rails For Java Programmers
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 

Viewers also liked

The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
Debugging With Symfony
Debugging With SymfonyDebugging With Symfony
Debugging With Symfony
Stefan Koopmanschap
 
Plugins And Making Your Own
Plugins And Making Your OwnPlugins And Making Your Own
Plugins And Making Your Own
Lambert Beekhuis
 
PHP, Cloud And Microsoft Symfony Live 2010
PHP,  Cloud And  Microsoft    Symfony  Live 2010PHP,  Cloud And  Microsoft    Symfony  Live 2010
PHP, Cloud And Microsoft Symfony Live 2010
guest5a7126
 
Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Fabien Potencier
 
Decoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCRDecoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCR
Henri Bergius
 
What Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHPWhat Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHP
Jan Unger
 
Symfony Internals
Symfony InternalsSymfony Internals
Symfony Internals
Geoffrey Bachelet
 
OkAPI meet symfony, symfony meet OkAPI
OkAPI meet symfony, symfony meet OkAPIOkAPI meet symfony, symfony meet OkAPI
OkAPI meet symfony, symfony meet OkAPI
Lukas Smith
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2Hugo Hamon
 
How to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationHow to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross Application
Mike Taylor
 
Symfony in the Cloud
Symfony in the CloudSymfony in the Cloud
Symfony in the Cloud
Kris Wallsmith
 
Apostrophe
ApostropheApostrophe
Apostrophe
tompunk
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationJonathan Wage
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real World
Jonathan Wage
 
Developing for Developers
Developing for DevelopersDeveloping for Developers
Developing for Developers
Francois Zaninotto
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational Mapper
guesta3af58
 
Symfony and eZ Publish
Symfony and eZ PublishSymfony and eZ Publish
Symfony and eZ Publish
Jérôme Vieilledent
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
Fabien Potencier
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
Marcos Labad
 

Viewers also liked (20)

The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
Debugging With Symfony
Debugging With SymfonyDebugging With Symfony
Debugging With Symfony
 
Plugins And Making Your Own
Plugins And Making Your OwnPlugins And Making Your Own
Plugins And Making Your Own
 
PHP, Cloud And Microsoft Symfony Live 2010
PHP,  Cloud And  Microsoft    Symfony  Live 2010PHP,  Cloud And  Microsoft    Symfony  Live 2010
PHP, Cloud And Microsoft Symfony Live 2010
 
Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)Symfony As A Platform (Symfony Camp 2007)
Symfony As A Platform (Symfony Camp 2007)
 
Decoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCRDecoupling Content Management with Create.js and PHPCR
Decoupling Content Management with Create.js and PHPCR
 
What Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHPWhat Symfony Has To Do With My Garage - Home Automation With PHP
What Symfony Has To Do With My Garage - Home Automation With PHP
 
Symfony Internals
Symfony InternalsSymfony Internals
Symfony Internals
 
OkAPI meet symfony, symfony meet OkAPI
OkAPI meet symfony, symfony meet OkAPIOkAPI meet symfony, symfony meet OkAPI
OkAPI meet symfony, symfony meet OkAPI
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
How to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross ApplicationHow to Clear Cache in a Symfony Cross Application
How to Clear Cache in a Symfony Cross Application
 
Symfony in the Cloud
Symfony in the CloudSymfony in the Cloud
Symfony in the Cloud
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real World
 
Developing for Developers
Developing for DevelopersDeveloping for Developers
Developing for Developers
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational Mapper
 
Symfony and eZ Publish
Symfony and eZ PublishSymfony and eZ Publish
Symfony and eZ Publish
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Implementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing CompanyImplementing a Symfony Based CMS in a Publishing Company
Implementing a Symfony Based CMS in a Publishing Company
 

Similar to The new form framework

Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAXМихаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
DrupalSib
 
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_FormZend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_FormJeremy Kendall
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
Michelangelo van Dam
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
Michelangelo van Dam
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
Shinya Ohyanagi
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
Mariusz Kozłowski
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
John Cleveley
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
Michelangelo van Dam
 
SOLID PRINCIPLES
SOLID PRINCIPLESSOLID PRINCIPLES
SOLID PRINCIPLES
Luciano Queiroz
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
Neil Crookes
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
Jeroen van Dijk
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
Gérer vos objets
Gérer vos objetsGérer vos objets
Gérer vos objets
Thomas Gasc
 

Similar to The new form framework (20)

Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAXМихаил Крайнюк - Form API + Drupal 8: Form and AJAX
Михаил Крайнюк - Form API + Drupal 8: Form and AJAX
 
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_FormZend_Form to the Rescue - A Brief Introduction to Zend_Form
Zend_Form to the Rescue - A Brief Introduction to Zend_Form
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
SOLID PRINCIPLES
SOLID PRINCIPLESSOLID PRINCIPLES
SOLID PRINCIPLES
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Gérer vos objets
Gérer vos objetsGérer vos objets
Gérer vos objets
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 

The new form framework

  • 1. The new form framework Bernhard Schussek
  • 2. What is different in the new form framework?
  • 3. symfony 1.x User sfForm Controller Domain Model
  • 4. symfony 1.x User sfForm Business Logic Controller Domain Model
  • 5. symfony 1.x User sfForm Business Logic Controller Domain Model unit testable!!
  • 6. symfony 1.x User function configure() { unset($this['foo']); sfFormDoctrine / sfFormPropel unset($this['bar']); unset($this['moo']); unset($this['comeon!']); ... Domain Model
  • 10. Symfony 2 User Form Domain Model
  • 11. Symfony 2 User Presentation Form Domain Model Business Logic designed by you™
  • 12. Business Logic class Customer { public $name = 'Default'; public getGender(); public setGender($gender); }
  • 13. Business Logic Presentation class Customer Form { TextField public $name = 'Default'; public getGender(); ChoiceField public setGender($gender); }
  • 14. $form = new Form('customer', $customer, ...); $form->add(new TextField('name')); $form->add(new ChoiceField('gender', array( 'choices' => array('male', 'female'), )));
  • 15. $form = new Form('customer', $customer, ...); ... if (isset($_POST['customer'])) { $form->bind($_POST['customer']); }
  • 16. Business Logic Presentation class Customer Form { to-one relations FieldGroup public $address; }
  • 17. $group = new FieldGroup('address'); $group->add(...); $group->add(...); $group->add(...); $form->add($group);
  • 18. Business Logic Presentation class Customer Form { CollectionField to-many relations FieldGroup public $emails; FieldGroup }
  • 19. $group = new FieldGroup('emails'); $group->add(...); $group->add(...); $form->add(new CollectionField($group));
  • 20. Default Localized TextField NumberField TimeField TextareaField IntegerField DateTimeField CheckboxField PercentField TimezoneField ChoiceField MoneyField RepeatedField PasswordField DateField CollectionField HiddenField BirthdayField FieldGroup Special
  • 21. Field groups — light-weight subforms — compose other fields or field groups ? DateField ChoiceField ChoiceField CheckboxField CheckboxField
  • 23. <?php echo $form->renderFormTag('url') ?> <?php echo $form->renderErrors() ?> <?php echo $form->render() ?> <input type="submit" value="Submit" /> </form>
  • 24. <label for="<?php echo $form['name']->getId() ?>"> Enter a name </label> <?php echo $form['name']->renderErrors() ?> <?php echo $form['name']->render() ?>
  • 25. <?php echo $form['date']['day']->render() ?> <?php echo $form['date']['month']->render() ?> <?php echo $form['date']['year']->render() ?>
  • 27. symfony 1.x sfForm sfValidator Controller Domain Model Doctrine_Validator
  • 28. symfony 1.x sfForm sfValidator Controller Duplicate validation logic Domain Model Doctrine_Validator Failed validation leads to 505 errors
  • 29. Symfony 2 Form Domain Model
  • 30. Symfony 2 Form Validator Domain Model
  • 31. Symfony 2 Form Validator Domain Model Validation Metadata "how shall the domain model be validated?"
  • 32. Customer: properties: name: - MinLength: 6 birthday: - Date: ~ gender: - Choice: [male, female]
  • 33. <class name="Customer"> <property name="name"> <constraint name="MinLength">6</constraint> </property> <property name="birthday"> <constraint name="Date" /> </property> <property name="gender"> <constraint name="Choice"> <value>male</value> <value>female</value> </constraint> </property> </class>
  • 34. class Customer { /** @Validation({ @MinLength(6) }) */ public $name; /** @Validation({ @Choice({"male", "female"}) }) */ public function getGender(); /** @Validation({ @Valid }) */ public $gender; }
  • 35. Type Check String Other AssertTrue AssertType MinLength Min AssertFalse Date MaxLength Max Blank DateTime Regex Choice NotBlank Time Url Valid Null Email Collection NotNull File
  • 36. Constraints can be put on — Classes — Properties — Methods with a "get" or "is" prefix
  • 38. Independent from Symfony 2 Zend Doctrine 2 Propel
  • 39. How does all this fit into the form framework?
  • 40. $form = new Form('customer', $customer, $this->container->getService('validator'));
  • 42. The validation is launched automatically upon submission
  • 44. Q: What if my form does not translate 1:1 to a domain model?
  • 45. A: Then the domain model doesn't exist yet ;-)
  • 46. Use Case — Extend our form for a checkbox to accept terms and conditions — Should not be stored as field in the Customer class
  • 47. class Registration { /** @Validation({ @Valid }) */ public $customer; /** * @Validation({ * @AssertTrue(message="Please accept") * }) */ public $termsAccepted = false; public function process() { // save $customer, send emails etc. } }
  • 48. $form->add(new CheckboxField('termsAccepted')); $group = new FieldGroup('customer'); $group->add(new TextField('name')); ... $form->add($group);
  • 49. if ($form->isValid()) { $registration->process(); }
  • 50. The Registration class — can be reused (XML requests, …) — can be unit tested
  • 51. Q: What if I don't want to validate all attributes of an object?
  • 53. Use Case — Administrators should be able to create Customers with empty names — Normal users not
  • 54. class Customer { /** * @Validation({ * @NotBlank(groups="User") * }) */ public $name; ... }
  • 57. Constraint groups can be sequenced — first validate group "Fast" — then, if "Fast" was valid, validate group "Slow"