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

Source for file Parser.php

Documentation is available at Parser.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: Parser Base Class                              |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2005 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id$
  17. //
  18.  
  19. require_once 'Cache/Lite.php';
  20. require_once 'Image/GIS2/LineSet.php';
  21.  
  22. /**
  23.  * Parser Base Class.
  24.  *
  25.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @copyright   Copyright &copy; 2002-2005 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  28.  * @category    Image
  29.  * @package     Image_GIS2
  30.  */
  31. abstract class Image_GIS2_Parser {
  32.     /**
  33.     * Cache.
  34.     *
  35.     * @var Cache_Lite $cache 
  36.     */
  37.     protected $cache = NULL;
  38.  
  39.     /**
  40.     * Data Files.
  41.     *
  42.     * @var array $dataFiles 
  43.     */
  44.     protected $dataFiles = array();
  45.  
  46.     /**
  47.     * Set to TRUE to enable debugging.
  48.     *
  49.     * @var boolean $debug 
  50.     */
  51.     protected $debug;
  52.  
  53.     /**
  54.     * Line Set.
  55.     *
  56.     * @var array $lineSets 
  57.     */
  58.     protected $lineSets = array();
  59.  
  60.     /**
  61.     * Constructor.
  62.     *
  63.     * @param  boolean $cache 
  64.     * @param  boolean $debug 
  65.     * @access public
  66.     */
  67.     public function Image_GIS2_Parser($cache$debug{
  68.         if ($cache{
  69.             $this->cache = new Cache_Lite;
  70.         }
  71.  
  72.         $this->debug = $debug;
  73.     }
  74.  
  75.     /**
  76.     * Factory.
  77.     *
  78.     * @param  string  $parser 
  79.     * @param  boolean $cache 
  80.     * @param  boolean $debug 
  81.     * @return object 
  82.     * @access public
  83.     */
  84.     public static function factory($parser$cache$debug{
  85.         include_once 'Image/GIS2/Parser/' $parser '.php';
  86.  
  87.         $class  'Image_GIS2_Parser_' $parser;
  88.         $object = new $class($cache$debug);
  89.  
  90.         return $object;
  91.     }
  92.  
  93.     /**
  94.     * Adds a datafile to the map.
  95.     *
  96.     * @param  string  $dataFile 
  97.     * @param  mixed   $color 
  98.     * @access public
  99.     */
  100.     public function addDataFile($dataFile$color{
  101.         $this->dataFiles[$dataFile$color;
  102.     }
  103.  
  104.     /**
  105.     * Parses the data files of the map.
  106.     *
  107.     * @access public
  108.     * @return array 
  109.     */
  110.     public function parse({
  111.         foreach ($this->dataFiles as $dataFile => $color{
  112.             $cacheID md5($dataFile '_' $color);
  113.             $lineSet = false;
  114.  
  115.             if (is_object($this->cache&&
  116.                 $lineSet $this->cache->get($cacheID'Image_GIS')) {
  117.                 $lineSet unserialize($lineSet);
  118.             }
  119.  
  120.             if ($lineSet === false{
  121.                 $lineSet $this->parseFile($dataFile$color);
  122.  
  123.                 if (is_object($this->cache)) {
  124.                     $this->cache->save(serialize($lineSet)$cacheID'Image_GIS');
  125.                 }
  126.             }
  127.  
  128.             $this->lineSets[$lineSet;
  129.         }
  130.  
  131.         return $this->lineSets;
  132.     }
  133.  
  134.     /**
  135.     * Parses a data file.
  136.     *
  137.     * @param  string  $dataFile 
  138.     * @param  mixed   $color 
  139.     * @return mixed 
  140.     * @access public
  141.     * @abstract
  142.     */
  143.     public abstract function parseFile($dataFile$color);
  144. }
  145. ?>

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