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