Source for file FormGroup.php

Documentation is available at FormGroup.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette\Forms
  11. 11:  */
  12. 12:  
  13. 13:  
  14. 14:  
  15. 15: /**
  16. 16:  * A user group of form controls.
  17. 17:  *
  18. 18:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  19. 19:  * @package    Nette\Forms
  20. 20:  *
  21. 21:  * @property-read array $controls 
  22. 22:  * @property-read array $options 
  23. 23:  */
  24. 24: class FormGroup extends Object
  25. 25: {
  26. 26:     /** @var SplObjectStorage */
  27. 27:     protected $controls;
  28. 28:  
  29. 29:     /** @var array user options */
  30. 30:     private $options array();
  31. 31:  
  32. 32:  
  33. 33:  
  34. 34:     public function __construct()
  35. 35:     {
  36. 36:         $this->controls = new SplObjectStorage;
  37. 37:     }
  38. 38:  
  39. 39:  
  40. 40:  
  41. 41:     /**
  42. 42:      * @return FormGroup  provides a fluent interface
  43. 43:      */
  44. 44:     public function add()
  45. 45:     {
  46. 46:         foreach (func_get_args(as $num => $item{
  47. 47:             if ($item instanceof IFormControl{
  48. 48:                 $this->controls->attach($item);
  49. 49:  
  50. 50:             elseif ($item instanceof Traversable || is_array($item)) {
  51. 51:                 foreach ($item as $control{
  52. 52:                     $this->controls->attach($control);
  53. 53:                 }
  54. 54:  
  55. 55:             else {
  56. 56:                 throw new InvalidArgumentException("Only IFormControl items are allowed, the #$num parameter is invalid.");
  57. 57:             }
  58. 58:         }
  59. 59:         return $this;
  60. 60:     }
  61. 61:  
  62. 62:  
  63. 63:  
  64. 64:     /**
  65. 65:      * @return array IFormControl
  66. 66:      */
  67. 67:     public function getControls()
  68. 68:     {
  69. 69:         return iterator_to_array($this->controls);
  70. 70:     }
  71. 71:  
  72. 72:  
  73. 73:  
  74. 74:     /**
  75. 75:      * Sets user-specific option.
  76. 76:      *
  77. 77:      * Options recognized by ConventionalRenderer
  78. 78:      * - 'label' - textual or Html object label
  79. 79:      * - 'visual' - indicates visual group
  80. 80:      * - 'container' - container as Html object
  81. 81:      * - 'description' - textual or Html object description
  82. 82:      * - 'embedNext' - describes how render next group
  83. 83:      *
  84. 84:      * @param  string key
  85. 85:      * @param  mixed  value
  86. 86:      * @return FormGroup  provides a fluent interface
  87. 87:      */
  88. 88:     public function setOption($key$value)
  89. 89:     {
  90. 90:         if ($value === NULL{
  91. 91:             unset($this->options[$key]);
  92. 92:  
  93. 93:         else {
  94. 94:             $this->options[$key$value;
  95. 95:         }
  96. 96:         return $this;
  97. 97:     }
  98. 98:  
  99. 99:  
  100. 100:  
  101. 101:     /**
  102. 102:      * Returns user-specific option.
  103. 103:      * @param  string key
  104. 104:      * @param  mixed  default value
  105. 105:      * @return mixed 
  106. 106:      */
  107. 107:     final public function getOption($key$default NULL)
  108. 108:     {
  109. 109:         return isset($this->options[$key]$this->options[$key$default;
  110. 110:     }
  111. 111:  
  112. 112:  
  113. 113:  
  114. 114:     /**
  115. 115:      * Returns user-specific options.
  116. 116:      * @return array 
  117. 117:      */
  118. 118:     final public function getOptions()
  119. 119:     {
  120. 120:         return $this->options;
  121. 121:     }
  122. 122: