This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$form = new Form(); | |
$form->bind($request, $data); | |
assert true === $form->isBound(); | |
// if request is post, form was submitted | |
assert true === $form->isXXX(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a) Importing the namespace only | |
<?php | |
use Symfony\Component\Form | |
class ContactForm extends Form\Form | |
{ | |
protected function configure() | |
{ | |
$this->add(new Form\TextField('subject', array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using a static Options class with utility functions | |
+ Type hints (because setters are called) | |
+ Options are set in the very beginning of the constructor | |
+ Good performance | |
+ Everything is a property, no special treatment of options | |
- Verbose | |
- No error if unsupported options are given |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using a static OptionSupport class that automatically writes options into properties | |
+ Options are set in the very beginning of the constructor | |
+ Concise | |
+ Error if option is not supported | |
+ Everything is a property, no special treatment of options | |
~ Medium performance. Reflection is slow, but some things can be cached so it is faster than addOption() | |
- Options need to be converted to camel case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The current way, using addOption(), addRequiredOption() and getOption() | |
+ Concise | |
+ Error if option is not supported | |
- Slow, because the addOption() calls are executed for every new instance | |
- Base class Configurable needed | |
- Overriding options in parent fields very intransparent | |
- Options need special treatment ($this->required vs. $this->getOption('required')) | |
- Problems with accessing required options before parent::__construct() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Services for a bundle are always loaded | |
# hello configLoad() will be called automatically (if defined) | |
# Namespaces can be simplified | |
doctrine: | |
dbal: | |
dbname: xxxxxxxx | |
user: xxxxxxxx | |
password: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctrine: | |
dbal: | |
dbname: xxxxxxxx | |
user: xxxxxxxx | |
password: ~ | |
logging: %kernel.debug% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using a static OptionSupport class that automatically writes options into properties AND fields extend it. | |
+ Options are set in the very beginning of the constructor | |
+ Concise | |
+ Error if option is not supported | |
+ Everything is a property, no special treatment of options | |
+ Good performance | |
+ Static options can be hidden from public access | |
- Private properties wouldn't work, access not allowed from parent classes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone git://github.com/bschussek/symfony-sandbox.git | |
cd symfony-sandbox | |
git checkout -b hacking workshop-start | |
cp app/config/doctrine.yml-dist app/config/doctrine.yml | |
app/console doctrine:database:create | |
app/console doctrine:schema:create | |
app/console doctrine:data:load |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Sensio\HelloBundle; | |
use Symfony\Component\Form\FormFactory; | |
use Sensio\HelloBundle\Entity\Post; | |
use Sensio\HelloBundle\Entity\Comment; | |
class HelloFormFactory | |
{ |