PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/solar/1.1.1/source/solar/Solar/View/Helper/FormElement.php

http://github.com/pmjones/php-framework-benchmarks
PHP | 170 lines | 51 code | 16 blank | 103 comment | 0 complexity | 2d6a680da4ad1afb073cfdae5e80ceda MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. *
  4. * Abstract helper for form elements.
  5. *
  6. * @category Solar
  7. *
  8. * @package Solar_View_Helper_Form
  9. *
  10. * @author Paul M. Jones <pmjones@solarphp.com>
  11. *
  12. * @license http://opensource.org/licenses/bsd-license.php BSD
  13. *
  14. * @version $Id: FormElement.php 3409 2008-09-20 18:04:17Z pmjones $
  15. *
  16. */
  17. abstract class Solar_View_Helper_FormElement extends Solar_View_Helper {
  18. /**
  19. *
  20. * Default form element information.
  21. *
  22. * @var array
  23. *
  24. */
  25. protected $_info = array(
  26. 'type' => '',
  27. 'name' => '',
  28. 'value' => '',
  29. 'label' => '',
  30. 'attribs' => '',
  31. 'options' => array(),
  32. 'require' => false,
  33. 'disable' => false,
  34. 'invalid' => array(),
  35. );
  36. /**
  37. *
  38. * The order in which to process info keys.
  39. *
  40. * Attribs is last so that attributes are unset properly.
  41. *
  42. * @var array
  43. *
  44. */
  45. protected $_keys = array(
  46. 'type',
  47. 'name',
  48. 'value',
  49. 'label',
  50. 'options',
  51. 'require',
  52. 'disable',
  53. 'invalid',
  54. 'attribs',
  55. );
  56. /**
  57. *
  58. * The form element type (text, radio, etc).
  59. *
  60. * @var string
  61. *
  62. */
  63. protected $_type;
  64. /**
  65. *
  66. * The form element name.
  67. *
  68. * @var string
  69. *
  70. */
  71. protected $_name;
  72. /**
  73. *
  74. * The form element value.
  75. *
  76. * @var string
  77. *
  78. */
  79. protected $_value;
  80. /**
  81. *
  82. * The form element label.
  83. *
  84. * @var string
  85. *
  86. */
  87. protected $_label;
  88. /**
  89. *
  90. * The form element attributes (checked, selected, readonly, etc).
  91. *
  92. * @var array
  93. *
  94. */
  95. protected $_attribs;
  96. /**
  97. *
  98. * Options for checkbox, select, and radio elements.
  99. *
  100. * @var array
  101. *
  102. */
  103. protected $_options;
  104. /**
  105. *
  106. * Whether or not the element is required.
  107. *
  108. * @var bool
  109. *
  110. */
  111. protected $_require;
  112. /**
  113. *
  114. * Whether or not the element is to be disabled.
  115. *
  116. * @var bool
  117. *
  118. */
  119. protected $_disable;
  120. /**
  121. *
  122. * Feedback messages for the element.
  123. *
  124. * @var bool
  125. *
  126. */
  127. protected $_invalid;
  128. /**
  129. *
  130. * Prepares an info array and imports to the properties.
  131. *
  132. * @param array $info An array of element information.
  133. *
  134. * @return void
  135. *
  136. */
  137. protected function _prepare($info)
  138. {
  139. $info = array_merge($this->_info, $info);
  140. settype($info['type'], 'string');
  141. settype($info['name'], 'string');
  142. settype($info['label'], 'string');
  143. settype($info['attribs'], 'array');
  144. settype($info['options'], 'array');
  145. settype($info['require'], 'bool');
  146. settype($info['disable'], 'bool');
  147. settype($info['invalid'], 'array');
  148. foreach ($this->_keys as $key) {
  149. unset($info['attribs'][$key]);
  150. $prop = "_$key";
  151. $this->$prop = $info[$key];
  152. }
  153. }
  154. }