Source for file LDAPAgentIterator.class.php

Documentation is available at LDAPAgentIterator.class.php

  1. <?php
  2.  
  3. require_once(OKI2."/osid/agent/AgentIterator.php");
  4. require_once(HARMONI."oki2/shared/HarmoniIterator.class.php");
  5.  
  6. /**
  7. * AgentIterator provides access to these objects sequentially, one at a time.
  8. * The purpose of all Iterators is to to offer a way for OSID methods to
  9. * return multiple values of a common type and not use an array. Returning an
  10. * array may not be appropriate if the number of values returned is large or
  11. * is fetched remotely. Iterators do not allow access to values by index,
  12. * rather you must access values in sequence. Similarly, there is no way to go
  13. * backwards through the sequence unless you place the values in a data
  14. * structure, such as an array, that allows for access by index.
  15. *
  16. * <p>
  17. * OSID Version: 2.0
  18. * </p>
  19. *
  20. * @package harmoni.osid_v2.agent
  21. *
  22. * @copyright Copyright &copy; 2005, Middlebury College
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  24. *
  25. * @version $Id: LDAPAgentIterator.class.php,v 1.3 2007/09/04 20:25:37 adamfranco Exp $
  26. */
  27. class LDAPAgentIterator
  28. extends HarmoniAgentIterator
  29. // implements AgentIterator
  30.  
  31. {
  32. /**
  33. * @var object $_nodeIterator;
  34. * @access private
  35. * @since 8/30/05
  36. */
  37. var $_dns;
  38. /**
  39. * @var object $_agents;
  40. * @access private
  41. * @since 2/27/06
  42. */
  43. var $_agents;
  44. /**
  45. * Constructor
  46. *
  47. * @param object LDAPAuthNMethod $authNMethod
  48. * @param ref array $agents An array of agents to populate with our created
  49. * Agent objects
  50. * @param optional array $dns
  51. * @return object
  52. * @access public
  53. * @since 8/30/05
  54. */
  55. function LDAPAgentIterator ( $authNMethod, $agents, $dns = array() ) {
  56. // determine the count (if we are passed dns, or just a poplulated $agents array)
  57. if (count($dns) > count($agents))
  58. $this->_count = count($dns);
  59. else
  60. $this->_count = count($agents);
  61. $this->_current = 0;
  62. $this->_authNMethod =$authNMethod;
  63. $this->_agents =$agents;
  64. $this->_dns = $dns;
  65. }
  66. /**
  67. * Return true if there is an additional Agent ; false otherwise.
  68. *
  69. * @return boolean
  70. *
  71. * @throws object AgentException An exception with one of the
  72. * following messages defined in org.osid.agent.AgentException may
  73. * be thrown: {@link }
  74. * org.osid.agent.AgentException#OPERATION_FAILED
  75. * OPERATION_FAILED}, {@link }
  76. * org.osid.agent.AgentException#PERMISSION_DENIED
  77. * PERMISSION_DENIED}, {@link }
  78. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  79. * CONFIGURATION_ERROR}, {@link }
  80. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}
  81. *
  82. * @access public
  83. */
  84. function hasNext () {
  85. if ($this->_count == 0)
  86. return false;
  87. else
  88. return ($this->_current < $this->_count);
  89. }
  90.  
  91. /**
  92. * Return the next Agent.
  93. *
  94. * @return object Agent
  95. *
  96. * @throws object AgentException An exception with one of the
  97. * following messages defined in org.osid.agent.AgentException may
  98. * be thrown: {@link }
  99. * org.osid.agent.AgentException#OPERATION_FAILED
  100. * OPERATION_FAILED}, {@link }
  101. * org.osid.agent.AgentException#PERMISSION_DENIED
  102. * PERMISSION_DENIED}, {@link }
  103. * org.osid.agent.AgentException#CONFIGURATION_ERROR
  104. * CONFIGURATION_ERROR}, {@link }
  105. * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED},
  106. * {@link org.osid.agent.AgentException#NO_MORE_ITERATOR_ELEMENTS}
  107. * NO_MORE_ITERATOR_ELEMENTS}
  108. *
  109. * @access public
  110. */
  111. function next () {
  112. if (!isset($this->_agents[$this->_current])) {
  113. $authenticationManager = Services::getService("AuthN");
  114. $agentManager = Services::getService("AgentManager");
  115. if (!isset($this->_dns[$this->_current]))
  116. throwError(new Error("Tried to get Group for un-passed dn", "LDAPAgentIterator", true));
  117. $tokens =$this->_authNMethod->createTokensForIdentifier($this->_dns[$this->_current]);
  118. $agentId =$authenticationManager->_getAgentIdForAuthNTokens($tokens, $this->_authNMethod->getType());
  119. $this->_agents[$this->_current] =$agentManager->getAgent($agentId);
  120. }
  121. $agent =$this->_agents[$this->_current];
  122. $this->_current++;
  123. return $agent;
  124. }
  125. /**
  126. * Gives the number of items in the iterator
  127. *
  128. * @return integer
  129. * @access public
  130. * @since 8/31/05
  131. */
  132. function count () {
  133. return count($this->_count);
  134. }
  135. }
  136.  
  137. ?>

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