Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface IBuilder
- {
- function buildField($name, $label);
- }
- class Builder implements IBuilder
- {
- private $form;
- public function __construct(Nette\Application\UI\Form $form)
- {
- $this->form = $form;
- }
- public function buildField($name, $label)
- {
- $this->form->addText($name, $label);
- }
- }
- class Director
- {
- private $builder;
- public function __construct(IBuilder $builder)
- {
- $this->builder = $builder;
- }
- // nemusí být nezbytně v parametru, možné nakonfigurovat i jinak
- public function build($config)
- {
- $this->builder->buildField($config->name, $config->label);
- // ...
- return $this->builder;
- }
- }
- $director = new Director(new Builder(new Nette\Application\UI\Form));
- $form = $director->build((object)array(
- 'name' => 'sex',
- 'label' => 'Pohlaví'
- ));
- echo $form;
Advertisement
Add Comment
Please, Sign In to add comment