Source for file ResultConverter.php

Documentation is available at ResultConverter.php

  1. <?php
  2. require_once RDFAPI_INCLUDE_DIR 'sparql/SparqlEngineDb/ResultRenderer.php';
  3.  
  4. /**
  5. *   Converts a database result into a proper
  6. *   rdf statement triple array
  7. *
  8. *   @author Christian Weiske <cweiske@cweiske.de>
  9. *
  10. *   @package sparql
  11. */
  12. {
  13.     /**
  14.     *   Determines the correct renderer and calls it.
  15.     *
  16.     *   The $resultform may be:
  17.     *   - false: The default renderer is taken then
  18.     *   - an object that implements SparqlEngineDb_ResultRenderer interface
  19.     *   - a string like "HTML" or "XML". The appropriate renderer is used then.
  20.     *   - a full class name, e.g. SparqlEngineDb_ResultRenderer_XML
  21.     *
  22.     *   @param array    $arRecordSets   Array of anything ADOConnection::Execute() can return
  23.     *   @param SparqlEngineDb $engine   Sparql database engine.
  24.     *   @param mixed    $resultform     Which format the results shall be in (false or "xml")
  25.     *
  26.     *   @return mixed   Most likely an array or a boolean value,
  27.     *                    or anything else as determined by $resultform
  28.     */
  29.     public static function convertFromDbResults($arRecordSetsSparqlEngineDb $engine$resultform false)
  30.     {
  31.         if (is_object($resultform)) {
  32.             if ($resultform instanceof SparqlEngineDb_ResultRenderer{
  33.                 return $resultform->convertFromDbResults(
  34.                     $arRecordSets,
  35.                     $engine->getQuery(),
  36.                     $engine
  37.                 );
  38.             else {
  39.                 throw new Exception(
  40.                     'Result renderer object needs to implement'
  41.                     . ' SparqlEngineDb_ResultRenderer interface'
  42.                 );
  43.             }
  44.         }
  45.  
  46.         if ($resultform === false{
  47.             $resultform 'Default';
  48.         else if ($resultform == 'xml'{
  49.             //kept for BC reasons
  50.             $resultform 'XML';
  51.         }
  52.  
  53.         if ($strClass self::loadClass($resultform)) {
  54.             $rrObj new $strClass();
  55.             if ($rrObj instanceof SparqlEngineDb_ResultRenderer{
  56.                 return $rrObj->convertFromDbResults(
  57.                     $arRecordSets,
  58.                     $engine->getQuery(),
  59.                     $engine
  60.                 );
  61.             else {
  62.                 throw new Exception(
  63.                     'Result renderer class "' $strClass '" needs to implement'
  64.                     . ' SparqlEngineDb_ResultRenderer interface'
  65.                 );
  66.             }
  67.         else {
  68.             throw new Exception(
  69.                 'Result renderer class "' $resultform '" could not be loaded.'
  70.             );
  71.         }
  72.     }//public static function convertFromDbResults($arRecordSets, SparqlEngineDb $engine, $resultform = false)
  73.  
  74.  
  75.  
  76.     /**
  77.     *   Tries to load a given class if it doesn't exist,
  78.     *   and returns true if the class can be used.
  79.     *
  80.     *   @param string $strClass Classname
  81.     *   @return mixed Class name if the class is loaded and can be used, false if not.
  82.     */
  83.     protected static function loadClass($strClass)
  84.     {
  85.         if (class_exists($strClass)) {
  86.             return $strClass;
  87.         }
  88.  
  89.         //RAP style, shortcut notation
  90.         $strFile 'SparqlEngineDb/ResultRenderer/' $strClass '.php';
  91.         @include_once RDFAPI_INCLUDE_DIR 'sparql/' $strFile;
  92.         if (class_exists('SparqlEngineDb_ResultRenderer_' $strClass)) {
  93.             return 'SparqlEngineDb_ResultRenderer_' $strClass;
  94.         }
  95.  
  96.         //RAP style
  97.         $strFile str_replace('_''/'$strClass'.php';
  98.         @include_once RDFAPI_INCLUDE_DIR 'sparql/' $strFile;
  99.         if (class_exists($strClass)) {
  100.             return $strClass;
  101.         }
  102.  
  103.         //PEAR style
  104.         @include_once $strFile;
  105.         if (class_exists($strClass)) {
  106.             return $strClass;
  107.         }
  108.  
  109.         return false;
  110.     }//protected static function loadClass($strClass)
  111.  
  112. }//class SparqlEngineDb_ResultConverter
  113. ?>

Documentation generated on Fri, 1 Jun 2007 16:51:40 +0200 by phpDocumentor 1.3.2