Source for file outputformatter.php

Documentation is available at outputformatter.php

  1. <?php
  2. /**
  3. * Output formatter object that controls output of other objects with sprintf statements
  4. *
  5. @author    Stuart Prescott
  6. @copyright  Copyright Stuart Prescott
  7. @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  8. @version    $Id$
  9. @package    Bumblebee
  10. @subpackage FormsLibrary
  11. */
  12.  
  13. /** Load ancillary functions */
  14. require_once 'inc/typeinfo.php';
  15.  
  16. /**
  17. * Output formatter object that controls output of other objects with sprintf statements
  18. *
  19. @package    Bumblebee
  20. @subpackage FormsLibrary
  21. */
  22. class OutputFormatter {
  23.   /** @var string  sprintf format string for this formatter  */
  24.   var $format;
  25.   /** @var mixed   field name or array of names (keys to $data) to format using this formatter */
  26.   var $formatfields;
  27.  
  28.  /**
  29.   *  Create a new OutputFormatter object
  30.   *
  31.   * @param string $format  see $this->format
  32.   * @param mixed $fields  string or array, see $this->fields
  33.   */
  34.    function OutputFormatter($format$fields{
  35.     $this->format = $format;
  36.     $this->formatfields = $fields;
  37.   }
  38.  
  39.   /**
  40.   * Format the data
  41.   *
  42.   * @param array $data     data to be formatted, $data[$formatfields[$i]]
  43.   * @return string formatted data
  44.   */
  45.   function format($data{
  46.     #echo "Formatting string";
  47.     $fields is_array($this->formatfields$this->formatfields : array($this->formatfields);
  48.     $s array();
  49.     foreach ($fields as $v{
  50.       if (is_object($v)) {
  51.         if (isset($data[$v])) {
  52.           $val = isset($data[$v]xssqw($data[$v]'';
  53.           if ($val !== '' && $val !== NULL$s[$val;
  54.         }
  55.       else {
  56.         $val $v->format($data);
  57.         if ($val !== '' && $val !== NULL$s[$val;
  58.       }
  59.     }
  60.     return count($svsprintf($this->format$s'';
  61.   }
  62.  
  63. // class OutputFormatter
  64.  
  65. ?>

Documentation generated on Tue, 06 Mar 2007 10:01:47 +0000 by phpDocumentor 1.3.0