HosipLan

Untitled

May 26th, 2011
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. interface IBuilder
  3. {
  4.    
  5.     function buildField($name, $label);
  6.  
  7. }
  8.  
  9. class Builder implements IBuilder
  10. {
  11.     private $form;
  12.    
  13.     public function __construct(Nette\Application\UI\Form $form)
  14.     {
  15.         $this->form = $form;
  16.     }
  17.  
  18.     public function buildField($name, $label)
  19.     {
  20.         $this->form->addText($name, $label);
  21.     }
  22.  
  23. }
  24.  
  25.  
  26. class Director
  27. {
  28.     private $builder;
  29.  
  30.     public function __construct(IBuilder $builder)
  31.     {
  32.         $this->builder = $builder;
  33.     }
  34.  
  35.     // nemusí být nezbytně v parametru, možné nakonfigurovat i jinak
  36.     public function build($config)
  37.     {
  38.         $this->builder->buildField($config->name, $config->label);
  39.         // ...
  40.  
  41.         return $this->builder;
  42.     }
  43.  
  44. }
  45.  
  46.  
  47. $director = new Director(new Builder(new Nette\Application\UI\Form));
  48. $form = $director->build((object)array(
  49.     'name' => 'sex',
  50.     'label' => 'Pohlaví'
  51. ));
  52.  
  53. echo $form;
Advertisement
Add Comment
Please, Sign In to add comment