Source for file OsidContext.php

Documentation is available at OsidContext.php

  1. <?php
  2. /**
  3. * <p>
  4. * OsidContext holds contextual information that is shared by the application
  5. * and the OSID implementations it uses. The osid package has some design
  6. * constraints that create the need for OsidContext. They are:
  7. *
  8. * <ul>
  9. * <li>
  10. * OSIDs must work with all frameworks.
  11. * </li>
  12. * <li>
  13. * OSID implementations are independent of each other.
  14. * </li>
  15. * </ul>
  16. *
  17. * These design constraints mean that there this no obvious place to put global
  18. * information. The OsidContext argument of the OsidLoader.getManager method
  19. * is intended to provide access to information that is global to an
  20. * application and the OSID implementations that it loads. OsidContext can
  21. * hold and retrieve context. The only requirement is that the information is
  22. * serializable. There are OsidContext methods to get and assign context.
  23. * </p>
  24. *
  25. * <p>
  26. * With few exceptions OSID objects are interfaces and not classes. The use of
  27. * interfaces in the definition of OSID objects has some important
  28. * characteristics:
  29. *
  30. * <ul>
  31. * <li>
  32. * There is no OSID framework for storing contextual (global) information.
  33. * </li>
  34. * <li>
  35. * The OSID implementation developer can define OSID objects by implementing
  36. * the OSID interface and extending a framework class.
  37. * </li>
  38. * <li>
  39. * Contextual (global) information can only be communicated when the
  40. * application loads an implementation.
  41. * </li>
  42. * </ul>
  43. *
  44. * These characteristics of OSIDs and the need to provide sharable contextual
  45. * (global) information led to the definition of OsidContext. An application
  46. * is responsible for supplying a valid OsidContext instance when it loads an
  47. * OSID implementation using the OsidLoader.getManager method. This approach
  48. * provides all the benefits and limitations of any system of global data.
  49. * </p>
  50. *
  51. * <p>
  52. * OsidContext uses an unambiguous String as a key to assign the serializable
  53. * context information. To retrieve the contextual information from the
  54. * OsidContext the getContext method is called with the key.
  55. * </p>
  56. *
  57. * <p>
  58. * OSID Version: 2.0
  59. * </p>
  60. *
  61. * <p>
  62. * Licensed under the {@link org.osid.SidImplementationLicenseMIT MIT}
  63. * O.K.I&#46; OSID Definition License}.
  64. * </p>
  65. *
  66. * @package org.osid
  67. */
  68. class OsidContext
  69. extends stdClass
  70. {
  71. /**
  72. * Assign the context of the OsidContext. Context is associated with an
  73. * unambiguous key, for example the context's fully qualified class name.
  74. * There is only one context asscociated with a particular key. If a
  75. * context already exists for this key, that context is overwritten.
  76. *
  77. * @param string $key
  78. * @param object mixed $context (original type: java.io.Serializable)
  79. *
  80. * @throws object OsidException An exception with one of the following
  81. * messages defined in org.osid.OsidException: {@link }
  82. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  83. *
  84. * @access public
  85. */
  86. function assignContext ( $key, $context )
  87. {
  88. if (!is_array($this->contextInfo))
  89. $this->contextInfo = array();
  90. if ((null != $key) && (null != $context)) {
  91. $this->contextInfo[serialize($key)] =$context;
  92. } else if ((null != $key) && (null == $context)) {
  93. if (isset($this->contextInfo[serialize($key)])) {
  94. unset($this->contextInfo[serialize($key)]);
  95. }
  96. } else {
  97. die(NULL_ARGUMENT);
  98. }
  99. }
  100.  
  101. /**
  102. * Get the context associated with this key. If the key is unknown, null
  103. * is returned.
  104. *
  105. * @param string $key
  106. *
  107. * @return object mixed (original type: java.io.Serializable)
  108. *
  109. * @throws object OsidException An exception with one of the following
  110. * messages defined in org.osid.OsidException: {@link }
  111. * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  112. *
  113. * @access public
  114. */
  115. function getContext ( $key )
  116. {
  117. if (null != $key) {
  118. if ($this->contextInfo[serialize($key)]) {
  119. return $this->contextInfo[serialize($key)];
  120. } else {
  121. return null;
  122. }
  123. }
  124.  
  125. die(NULL_ARGUMENT);
  126. }
  127.  
  128.  
  129. /**
  130. * Constructor
  131. */
  132. function OsidContext () {
  133. $this->contextInfo = array();
  134. }
  135. }
  136.  
  137. ?>

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