home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / GIS / Parser.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.7 KB  |  146 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: Parser Base Class                              |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 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: Parser.php,v 1.13 2004/04/17 10:21:24 sebastian Exp $
  17. //
  18.  
  19. require_once 'Cache/Lite.php';
  20. require_once 'Image/GIS/LineSet.php';
  21.  
  22. /**
  23.  * Parser Base Class.
  24.  *
  25.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @copyright   Copyright © 2002-2004 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_GIS
  30.  */
  31. class Image_GIS_Parser {
  32.     /**
  33.     * Cache.
  34.     *
  35.     * @var Cache_Lite $cache
  36.     */
  37.     var $cache = NULL;
  38.  
  39.     /**
  40.     * Data Files.
  41.     *
  42.     * @var array $dataFiles
  43.     */
  44.     var $dataFiles = array();
  45.  
  46.     /**
  47.     * Set to TRUE to enable debugging.
  48.     *
  49.     * @var boolean $debug
  50.     */
  51.     var $debug;
  52.  
  53.     /**
  54.     * Line Set.
  55.     *
  56.     * @var array $lineSets
  57.     */
  58.     var $lineSets = array();
  59.  
  60.     /**
  61.     * Constructor.
  62.     *
  63.     * @param  boolean $cache
  64.     * @param  boolean $debug
  65.     * @access public
  66.     */
  67.     function Image_GIS_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.     function &factory($parser, $cache, $debug) {
  85.         include_once 'Image/GIS/Parser/' . $parser . '.php';
  86.  
  87.         $class  = 'Image_GIS_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.     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.     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.     function parseFile($dataFile, $color) { /* abstract */ }
  144. }
  145. ?>
  146.