Source for file HarmoniProperties.class.php

Documentation is available at HarmoniProperties.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/shared/Properties.php");
  4. require_once(HARMONI."oki2/shared/HarmoniObjectIterator.class.php");
  5.  
  6.  
  7. /**
  8. * Properties is a mechanism for returning read-only data about an object. An
  9. * object can have data associated with a PropertiesType. For each
  10. * PropertiesType, there are Properties which are Serializable values
  11. * identified by a key.
  12. *
  13. * <p>
  14. * OSID Version: 2.0
  15. * </p>
  16. *
  17. * @package harmoni.osid_v2.shared
  18. *
  19. * @copyright Copyright &copy; 2005, Middlebury College
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  21. *
  22. * @version $Id: HarmoniProperties.class.php,v 1.17 2007/09/04 20:25:48 adamfranco Exp $
  23. */
  24. class HarmoniProperties
  25. extends Properties
  26. {
  27.  
  28. /**
  29. * Constructor. Create a new Properties object.
  30. *
  31. * @param object Type $type
  32. * @return object
  33. * @access public
  34. * @since 11/18/04
  35. */
  36. function HarmoniProperties ($type) {
  37. ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"), true);
  38. $this->_type = $type;
  39. $this->_properties = array();
  40. }
  41.  
  42. /**
  43. * Get the Type for this Properties instance.
  44. *
  45. * @return object Type
  46. *
  47. * @throws object SharedException An exception with one of the
  48. * following messages defined in org.osid.shared.SharedException
  49. * may be thrown: {@link }
  50. * org.osid.shared.SharedException#UNKNOWN_TYPE UNKNOWN_TYPE},
  51. * {@link org.osid.shared.SharedException#PERMISSION_DENIED}
  52. * PERMISSION_DENIED}, {@link }
  53. * org.osid.shared.SharedException#CONFIGURATION_ERROR
  54. * CONFIGURATION_ERROR}, {@link }
  55. * org.osid.shared.SharedException#UNIMPLEMENTED UNIMPLEMENTED}
  56. *
  57. * @access public
  58. */
  59. function getType () {
  60. return $this->_type;
  61. }
  62.  
  63. /**
  64. * Get the Property associated with this key.
  65. *
  66. * @param object mixed $key (original type: java.io.Serializable)
  67. *
  68. * @return object mixed (original type: java.io.Serializable)
  69. *
  70. * @throws object SharedException An exception with one of the
  71. * following messages defined in org.osid.shared.SharedException
  72. * may be thrown: {@link }
  73. * org.osid.shared.SharedException#UNKNOWN_TYPE UNKNOWN_TYPE},
  74. * {@link org.osid.shared.SharedException#PERMISSION_DENIED}
  75. * PERMISSION_DENIED}, {@link }
  76. * org.osid.shared.SharedException#CONFIGURATION_ERROR
  77. * CONFIGURATION_ERROR}, {@link }
  78. * org.osid.shared.SharedException#UNIMPLEMENTED UNIMPLEMENTED},
  79. * {@link org.osid.shared.SharedException#UNKNOWN_KEY UNKNOWN_KEY}
  80. *
  81. * @access public
  82. */
  83. function getProperty ( $key ) {
  84. if (!isset($this->_properties[serialize($key)]))
  85. return null;
  86. return $this->_properties[serialize($key)];
  87. }
  88. /**
  89. * Get the Keys associated with these Properties.
  90. *
  91. * @return object ObjectIterator
  92. *
  93. * @throws object SharedException An exception with one of the
  94. * following messages defined in org.osid.shared.SharedException
  95. * may be thrown: {@link }
  96. * org.osid.shared.SharedException#UNKNOWN_TYPE UNKNOWN_TYPE},
  97. * {@link org.osid.shared.SharedException#PERMISSION_DENIED}
  98. * PERMISSION_DENIED}, {@link }
  99. * org.osid.shared.SharedException#CONFIGURATION_ERROR
  100. * CONFIGURATION_ERROR}, {@link }
  101. * org.osid.shared.SharedException#UNIMPLEMENTED UNIMPLEMENTED}
  102. *
  103. * @access public
  104. */
  105. function getKeys () {
  106. $keys = array();
  107. foreach (array_keys($this->_properties) as $key) {
  108. $keys[] = unserialize($key);
  109. }
  110. $i = new HarmoniObjectIterator($keys);
  111. return $i;
  112. }
  113. /**
  114. * Add a Property to these Properties.
  115. *
  116. * WARNING: NOT IN OSID - This method is not in the OSIDs as of version 2.0
  117. * Use at your own risk
  118. *
  119. * Since PHP4's reference handling sucks royally and call-time-pass-by-reference
  120. * currently throws errors since it is depricated, there is no way to pass
  121. * objects as references and primatives by value to the same arguement. As such,
  122. * in order to allow Properties to hold references to objects (such as in an
  123. * Osid Context or Osid Configuration) the param-by reference must stay. To
  124. * pass strings or other primatives you must set the primatives to variables
  125. * first as in the following example:
  126. *
  127. * $configuration = new HarmoniProperties(new ConfigurationPropertiesType);
  128. * $configuration->addProperty('database_id', $arg1 = 0);
  129. * $configuration->addProperty('authentication_table', $arg2 = 'auth_db_user');
  130. * $configuration->addProperty('username_field', $arg3 = 'username');
  131. * $configuration->addProperty('password_field', $arg4 = 'password');
  132. * unset($arg1, $arg2, $arg3, $arg4);
  133. *
  134. * @param mixed $key
  135. * @param mixed $value
  136. * @return void
  137. * @access public
  138. * @since 11/18/04
  139. */
  140. function addProperty ( $key, $value ) {
  141. $this->_properties[serialize($key)] =$value;
  142. }
  143. /**
  144. * Remove a Property from these properties
  145. * WARNING: NOT IN OSID - This method is not in the OSIDs as of version 2.0
  146. * Use at your own risk
  147. */
  148. function deleteProperty($key){
  149. unset($this->_properties[serialize($key)]);
  150. }
  151. }

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