RDF
[ class tree: RDF ] [ index: RDF ] [ all elements ]

Source for file FindIterator.php

Documentation is available at FindIterator.php

  1. <?php
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: RDF_FindIterator
  5. // ----------------------------------------------------------------------------------
  6.  
  7. /**
  8.  * Iterator for traversing statements matching a searchpattern.
  9.  * RDF_FindIterators are returned by model->findAsIterator()
  10.  * Using a find iterator is significantly faster than using model->find() which returns
  11.  * a new result model.
  12.  * 
  13.  * @version  V0.81
  14.  * @author
  15.  *
  16.  * @package RDF
  17.  * @access  public
  18.  *
  19.  */
  20. class RDF_FindIterator extends RDF_Object
  21. {
  22.      /**
  23.     * Reference to the Model_Memory
  24.     * @var     object Model_Memory 
  25.     * @access  protected
  26.     */
  27.     var $model;
  28.  
  29.      /**
  30.     * Current position
  31.     * RDF_FindIterator does not use the build in PHP array iterator,
  32.     * so you can use serveral iterators on a single Model_Memory.
  33.     * @var     integer 
  34.     * @access  protected
  35.     */
  36.     var $position;
  37.  
  38.     /**
  39.     * Searchpattern
  40.     * 
  41.     * @var     Object Subject, Predicate, Object
  42.     * @access  protected
  43.     */
  44.     var $subject;
  45.     var $predicate;
  46.     var $object;
  47.  
  48.    /**
  49.     * Constructor
  50.     *
  51.     * @param    object  Model_Memory 
  52.     * @param    object  Subject 
  53.     * @param    object  Predicate 
  54.     * @param    object  Object 
  55.     * @access   public
  56.     */
  57.     function RDF_FindIterator(&$model&$sub&$pred&$obj)
  58.     {
  59.         $this->model =$model;
  60.         $this->subject =$sub;
  61.         $this->predicate =$pred;
  62.         $this->object =$obj;
  63.         $this->position = -1;
  64.     }
  65.  
  66.      /**
  67.     * Returns true if there are more matching statements.
  68.     * @return   boolean 
  69.     * @access   public
  70.     */
  71.     function hasNext()
  72.     {
  73.         if($this->model->findFirstMatchOff($this->subject$this->predicate$this->object($this->position+1)) > -1{
  74.             return true;
  75.         else {
  76.             return false;
  77.         }
  78.     }
  79.  
  80.     /**
  81.     * Returns the next matching statement.
  82.     * @return  tatement or NULL if there is no next matching statement.
  83.     * @access  public
  84.     */
  85.     function next()
  86.     {
  87.         $res $this->model->findFirstMatchOff($this->subject$this->predicate$this->object($this->position+1));
  88.         if ($res > -1{
  89.             $this->position=$res;
  90.             return $this->model->triples[$res];
  91.         else {
  92.             return null;
  93.         }
  94.     }
  95.  
  96.     /**
  97.     * Returns the current matching statement.
  98.     * @return  statement or NULL if there is no current matching statement.
  99.     * @access  public
  100.     */
  101.     function current()
  102.     {
  103.         if ($this->position >= -1 && isset($this->model->triples[$this->position])) {
  104.             return $this->model->triples[$this->position];
  105.         else {
  106.             return null;
  107.         }
  108.     }
  109. }
  110.  
  111. ?>

Documentation generated on Mon, 11 Mar 2019 15:39:28 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.