Source for file IterFind.php

Documentation is available at IterFind.php

  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------------
  4. * Class: IterFind
  5. * ----------------------------------------------------------------------------------
  6. *
  7. * @package utility
  8. */
  9.  
  10.  
  11. /**
  12. * Implementation of a find-iterator which delivers statements or quads.
  13. *
  14. * This Iterator should be used in a for-loop like:
  15. * for($iterator = $memmodel->iterFind(null,null,null,null); $iterator->valid(); $iterator->next())
  16. * {
  17. * $statement=$iterator->current();
  18. * };
  19. *
  20. * <BR><BR>History:
  21. * <LI>05-29-2005 : First version of this class.</LI>
  22. *
  23. * @version V0.9.1
  24. * @author Daniel Westphal (http://www.d-westphal.de)
  25. *
  26. *
  27. * @package utility
  28. * @access public
  29. ***/
  30. class IterFind
  31. {
  32. /**
  33. * The current position
  34. * @var integer
  35. * @access private
  36. */
  37. var $key;
  38. /**
  39. * boolean value, if the results should be returned as Quads
  40. * @var boolean
  41. * @access private
  42. */
  43. var $returnAsQuads;
  44. /**
  45. * If the current resource is valid
  46. * @var boolean
  47. * @access private
  48. */
  49. var $valid;
  50. /**
  51. * The current NamedGraph
  52. * @var obejct NamedGraph
  53. * @access private
  54. */
  55. var $current;
  56. /**
  57. * The graph to look in.
  58. * @var string
  59. * @access private
  60. */
  61. var $findGraph;
  62. /**
  63. * The subject Resource to search for
  64. * @var string
  65. * @access private
  66. */
  67. var $findSubject;
  68. /**
  69. * The predicate Resource to search for
  70. * @var string
  71. * @access private
  72. */
  73. var $findPredicate;
  74. /**
  75. * The object Resource to search for
  76. * @var string
  77. * @access private
  78. */
  79. var $findObject;
  80. /**
  81. * Constructor.
  82. *
  83. * $subject, $predicate, and $object are used like find().
  84. * $graph has to be a reference to the graph to search in.
  85. *
  86. *
  87. *
  88. * @param $graph Resource
  89. * @param $subject Resource
  90. * @param $predicate Resource
  91. * @param $object Resource
  92. * @param $returnAsQuads boolean
  93. * @access public
  94. */
  95. function IterFind($graph,$subject,$predicate,$object,$returnAsQuads=false)
  96. {
  97. if ($graph==NULL)
  98. {
  99. $this->valid=false;
  100. return;
  101. }
  102. $this->findGraph=&$graph;
  103. $this->findSubject=$subject;
  104. $this->findPredicate=$predicate;
  105. $this->findObject=$object;
  106. $this->rewind();
  107. $this->returnAsQuads=$returnAsQuads;
  108. }
  109. /**
  110. * Resets iterator list to start
  111. *
  112. * @access public
  113. */
  114. function rewind()
  115. {
  116. $this->key = -1;
  117. $this->next();
  118. }
  119. /**
  120. * Says if there are additional items left in the list
  121. *
  122. * @return boolean
  123. * @access public
  124. */
  125. function valid()
  126. {
  127. return $this->valid;
  128. }
  129. /**
  130. * Moves Iterator to the next item in the list
  131. *
  132. * @access public
  133. */
  134. function next()
  135. {
  136. $this->current = $this->findGraph->findFirstMatchingStatement($this->findSubject,$this->findPredicate,$this->findObject,++$this->key);
  137. $this->valid=($this->current!=NULL);
  138. }
  139. /**
  140. * Returns the current item
  141. *
  142. * @return mixed
  143. * @access public
  144. */
  145. function current()
  146. {
  147. if($this->returnAsQuads)
  148. return new Quad(new Resource($this->findGraph->getGraphName()),$this->current->getSubject(),$this->current->getPredicate(),$this->current->getObject());
  149. //else
  150. return $this->current;
  151. }
  152. /**
  153. * Returns the key of the current item
  154. *
  155. * @return integer
  156. * @access public
  157. */
  158. function key()
  159. {
  160. return $this->key;
  161. }
  162. }
  163. ?>

Documentation generated on Thu, 7 Jul 2005 13:41:50 +0200 by phpDocumentor 1.3.0RC3