Source for file FieldSet.class.php

Documentation is available at FieldSet.class.php

  1. <?php
  2.  
  3. //require_once(HARMONI."utilities/FieldSetValidator/FieldSet.interface.php");
  4.  
  5. /**
  6. * the FieldSet holds a set of key=value pairs of data
  7. *
  8. * @package harmoni.utilities.fieldsetvalidator
  9. *
  10. * @copyright Copyright &copy; 2005, Middlebury College
  11. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  12. *
  13. * @version $Id: FieldSet.class.php,v 1.7 2007/09/04 20:25:55 adamfranco Exp $
  14. */
  15. class FieldSet {
  16. /**
  17. * an associative array of keys and values
  18. *
  19. * @access private
  20. * @var mixed $_fields the associative array
  21. */
  22. var $_fields;
  23. /**
  24. * the constructor
  25. *
  26. * @param optional array $fields an associative array of key/value pairs to initialize with
  27. * @access public
  28. * @return void
  29. ***/
  30. function FieldSet( $fields = null ) {
  31. if ($fields && is_array($fields)) $this->_fields = $fields;
  32. else $this->clear();
  33. }
  34. /**
  35. * returns the value of $key
  36. *
  37. * @param string $key the key to return
  38. * @access public
  39. * @return mixed the value associated with $key
  40. ***/
  41. function get( $key ) {
  42. return $this->_fields[$key];
  43. }
  44. /**
  45. * returns an array of keys
  46. *
  47. * @access public
  48. * @return array an array of keys that are set
  49. ***/
  50. function getKeys() {
  51. if ($this->count()) return array_keys($this->_fields);
  52. return array();
  53. }
  54. /**
  55. * returns the number of fields set
  56. *
  57. * @access public
  58. * @return int the number of fields
  59. ***/
  60. function count() {
  61. return count($this->_fields);
  62. }
  63. /**
  64. * sets the value associated with $key to $val
  65. *
  66. * @param string $key the key
  67. * @param mixed $val the value to set $key to
  68. * @access public
  69. * @return void
  70. ***/
  71. function set( $key, $val ) {
  72. $this->_fields[$key] = $val;
  73. }
  74. /**
  75. * clears the fieldset
  76. *
  77. * @access public
  78. * @return void
  79. ***/
  80. function clear() {
  81. $this->_fields = array();
  82. }
  83. /**
  84. * unsets the specified key
  85. *
  86. * @param string $key the key to unset
  87. * @access public
  88. * @return int the number of fields
  89. ***/
  90. function unsetKey( $key ) {
  91. unset($this->_fields[$key]);
  92. }
  93. }
  94.  
  95. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:08 -0400 by phpDocumentor 1.3.0RC3