SourceForge.net LogoPHPGallue
[ class tree: libbase ] [ index: libbase ] [ all elements ]

Class: GALRowFactory

Source Location: /libbase/result.inc.php

Interface Overview


Interface for constructing rows.


Methods



Class Details

[line 219]
Interface for constructing rows.

This interface was introduced to allow to change the type of the row objects fetched from a GALResultIterator. As you don't call the constructor of GALRow yourself, it would difficult to introduce subclasses of GALRow: You had to override the GALResult::fetch() method in a subclass - and therefor you also had to override the GALDatabase::query() method... To solve this problem, GALDatabase and GALResult provide the GALDatabase::setResultFactory(), GALDatabase::getResultFactory(), GALDatabase::setTableFactory(), GALDatabase::getTableFactory(), GALRow::setRowFactory() and GALRow::getRowFactory() methods. GALDatabase and GALResult implement the GALResultFactory and GALTableFactory (respectively GALRowFactory) interfaces themselves and set themself as default factory. For example if you write a subclass of GALRow that implements a useful method, e.g output as HTML, you would write this subclass and another class that implements the GALRowFactory interface and constructs your class. Then you would set the row factory of a GALResult to an instance of your factory class.

  1.  class MyRowFactory implements GALRowFactory {
  2.      private $myGlobalData;
  3.      function __construct($myGlobalData{
  4.          $this->myGlobalData $myGlobalData;
  5.          // (...)
  6.      }
  7.      function buildRow(GALResult $source&$data{
  8.          return new MyRow($this->myGlobalData->importantInformation$source&$data);
  9.      }
  10.  }
  11.  class MyRow extends GALRow {
  12.      function __construct($myAdditionalInfo$source&$data{
  13.          parent::__construct($source&$data);
  14.          // (...)
  15.      }
  16.      function usefulMethodThatMissed({
  17.          // (...)
  18.      }
  19.      // (...)
  20.   }
  21.  
  22.  $users $database->query("SELECT * FROM `Users` WHERE `clue` > '0'");
  23.  $users->setRowFactory(new MyRowFactory($globalData));
  24.  while ($user $users->fetch()) {
  25.      echo $user->usefulMethodThatMissed();
  26.  }
  27.  
Note the changed signature of the constructor!




[ Top ]


Class Methods


method buildRow [line 227]

GALRow buildRow( GALResult $source, array &$data)

Builds a row.



Tags:



Parameters:

GALResult   $source  
array   &$data  

[ Top ]


Documentation generated on Wed, 16 Aug 2006 15:36:28 +0200 by phpDocumentor 1.3.0RC6