This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |
| class AuthorForm extends Form | |
| { | |
| protected function configure() | |
| { | |
| $this->setDataClass('Application\Entities\Author'); | |
| // 1. problem | |
This file contains hidden or 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 | |
| class OptionSupport | |
| { | |
| protected static $definitions = array(); | |
| public static function getDefinition($class) | |
| { | |
| if (!isset(self::$definitions[$class])) { | |
| self::$definitions[$class] = new OptionDefinition($class); |
This file contains hidden or 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
| // avoid session starting for bots | |
| $agents = array( | |
| 'googlebot', | |
| 'yahoo! slurp', | |
| 'baiduspider', | |
| 'sosospider', | |
| 'bingbot', | |
| 'nagios-plugins', | |
| ); |
This file contains hidden or 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 | |
| abstract class Configurable | |
| { | |
| private $options = array(); | |
| private $knownOptions = array(); | |
| private $requiredOptions = array(); |
This file contains hidden or 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 | |
| use Symfony\Foundation\UniversalClassLoader; | |
| require_once __DIR__.'/src/Symfony/Foundation/UniversalClassLoader.php'; | |
| $loader = new UniversalClassLoader(); | |
| $loader->registerNamespace('Symfony', __DIR__.'/src'); | |
| $loader->register(); |
This file contains hidden or 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
| Solution 1: | |
| Constraints can be defined on the top level. | |
| Advantages: | |
| Little code | |
| Disadvantage: | |
| Min does not have a context. If multiple constraints of the same type exist, | |
| they need to be wrapped in another annotation. |