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