Source for file Datastore.php

Documentation is available at Datastore.php

  1. <?php
  2. /**
  3. * Classe de base des datastore, Lier aux fichier de configuration
  4. *
  5. * PHP versions 5
  6. @category  PHP
  7. @package   GeoPrisma
  8. @author    Pascal Martin
  9. @copyright 2009, Boreal - Information Strategies
  10. @license   http://www.geoprisma.org/license BSD License
  11. @link      http://www.geoprisma.org
  12. */
  13.  
  14. /**
  15. * Classe de base des datastore, Lier aux fichier de configuration
  16. @category   PHP
  17. @package    GeoPrisma
  18. @subpackage Datastore
  19. @author     Pascal Martin
  20. */ 
  21. {
  22.     private $m_strName null;
  23.     private $m_objArrayLayers null;
  24.     private $m_objArrayOption null;
  25.     
  26.     /**
  27.     * @var org_geoprisma_service_Service 
  28.     */
  29.     private $m_objService null;
  30.  
  31.     /**
  32.     * Construit un nouvelle instance de org_geoprisma_datastore_Datastore
  33.     * 
  34.     * @param string                        $pstrName         Datastore name
  35.     * @param org_geoprisma_service_Service &$pobjService     Service object
  36.     * @param string                        $pstrLayers       String of layers
  37.     * @param array                         $pobjArrayOptions Datastore options
  38.     * 
  39.     * @return org_geoprisma_datastore_Datastore 
  40.     */
  41.     public function __construct(
  42.         $pstrName,
  43.         org_geoprisma_service_Service &$pobjService,
  44.         $pstrLayers=null,
  45.         $pobjArrayOptions=null
  46.     {
  47.         com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrName);
  48.  
  49.         // name
  50.         $this->m_strName $pstrName;
  51.  
  52.         // service
  53.         $this->m_objService $pobjService;
  54.  
  55.         // layers
  56.         if ($pstrLayers != null && $pstrLayers != ""
  57.         {
  58.             $this->m_objArrayLayers $this->getLayersFromString($pstrLayers);
  59.         }
  60.  
  61.         // options
  62.         $this->m_objArrayOption new ArrayObject();
  63.         if (is_array($pobjArrayOptions)) 
  64.         {
  65.             foreach ($pobjArrayOptions as $strOptionKey => $strOptionValue
  66.             {
  67.                 $this->m_objArrayOption->append(
  68.                     new org_geoprisma_option_Option(
  69.                         $strOptionKey,
  70.                         $strOptionValue
  71.                     )
  72.                 );     
  73.             }
  74.         }
  75.     }
  76.  
  77.     /**
  78.     * Extract layer names from a string
  79.     *
  80.     * @param string $pstrLayers Layers separated by ','
  81.     * 
  82.     * @return ArrayObject of string
  83.     */
  84.     private function getLayersFromString($pstrLayers)
  85.     {
  86.         $objArrayLayers new ArrayObject();    
  87.  
  88.         $objArrayLayersTemp explode(","$pstrLayers);
  89.         foreach ($objArrayLayersTemp as $strLayer)
  90.         {
  91.             $strLayer trim($strLayer);
  92.             if $strLayer != ""
  93.             {
  94.                 $objArrayLayers->append($strLayer);
  95.             }
  96.         }
  97.  
  98.         return $objArrayLayers;
  99.     }
  100.     
  101.     /**
  102.     * Check if the passed layer are authorized
  103.     * 
  104.     * @param string $pstrLayer Layer Name
  105.     * 
  106.     * @return boolean true or false
  107.     */
  108.     public function isAuthorizedLayer($pstrLayer)
  109.     {
  110.         com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrLayer);
  111.         if (array_search($pstrLayer(array)$this->m_objArrayLayers=== false
  112.         {
  113.             return false;          
  114.         }                
  115.         return true;      
  116.     }
  117.  
  118.     /**
  119.     * Return the DataStore name
  120.     *
  121.     * @return string 
  122.     */
  123.     public function getName()
  124.     {
  125.         return $this->m_strName;   
  126.     }
  127.     
  128.     /**
  129.     * Return the Service object linked to this DataStore
  130.     * 
  131.     * @return org_geoprisma_service_Service 
  132.     */
  133.     public function getService()
  134.     {
  135.         return $this->m_objService;   
  136.     }
  137.  
  138.     /**
  139.     * Return the layers array object
  140.     * 
  141.     * @return ArrayObject 
  142.     */
  143.     public function getLayers()
  144.     {
  145.         return $this->m_objArrayLayers;
  146.     }
  147.  
  148.     /**
  149.     * Get layer string (separated by ',')
  150.     *
  151.     * @return string 
  152.     */
  153.     public function getLayerString()
  154.     {
  155.         return implode(","(array)$this->getLayers());
  156.     }
  157.  
  158.     /**
  159.     * Get all datastore options
  160.     *
  161.     * @return ArrayObject 
  162.     */
  163.     public function getOptions()
  164.     {
  165.         return $this->m_objArrayOption;   
  166.     }
  167.     
  168.     /**
  169.     * Get a specific option using its name
  170.     * 
  171.     * @param string  $pstrName    Option name
  172.     * @param boolean $pbSkipError Whether the method should skip throwing an
  173.     *                              error if no option is found.
  174.     * 
  175.     * @return org_geoprisma_option_Option 
  176.     */
  177.     public function getOption($pstrName$pbSkipError=false)
  178.     {
  179.         if ($this->getOptions(!= null
  180.         {
  181.             foreach ($this->getOptions(as $objOption)   
  182.             {
  183.                 if ($objOption->getName(== $pstrName
  184.                 {
  185.                     return $objOption;
  186.                 }    
  187.             }
  188.         }
  189.  
  190.         if ($pbSkipError
  191.         {
  192.             return false;
  193.         }
  194.         else
  195.         {
  196.             throw new org_geoprisma_exception_OptionNotFoundException($pstrName);
  197.         }
  198.     }
  199.     
  200.     /**
  201.     *  Ajout le datastore courant (this) dans le xml
  202.     * 
  203.     * @param DOMElement  &$pobjDomElementDatastores Noeud xml ou le datastore doit Ãªtre ajouter
  204.     * @param DOMDocument &$pobjDomDocument          Document XMl ou le noeud xml datastore est ajouter, utiliser pour construire les noeuds
  205.     * 
  206.     * @return void 
  207.     */
  208.     public function insertIntoXML(DOMElement &$pobjDomElementDatastoresDOMDocument &$pobjDomDocument)
  209.     {
  210.         $objDomElementDatastore $pobjDomDocument->createElement('datastore')
  211.         $pobjDomElementDatastores->appendChild($objDomElementDatastore);        
  212.         $objDomElementName $pobjDomDocument->createElement('name'$this->getName())
  213.         $objDomElementService $pobjDomDocument->createElement('service'$this->getService()->getName());
  214.         $objDomElementDatastore->appendChild($objDomElementName);
  215.         $objDomElementDatastore->appendChild($objDomElementService);       
  216.         
  217.         // params with options
  218.         $objDomElementParams $this->getDomElements(
  219.             'params'$this->getOptions()$pobjDomDocument
  220.         );
  221.  
  222.         // params/layers adding
  223.         if ($this->getLayers(!= null
  224.         {
  225.             $objDomElementLayers $pobjDomDocument->createElement(
  226.                 'layers'$this->getLayerString()
  227.             )
  228.             $objDomElementParams->appendChild($objDomElementLayers);
  229.         }
  230.  
  231.         $objDomElementDatastore->appendChild($objDomElementParams);
  232.     }
  233.     
  234. }
  235.  
  236. ?>

Documentation generated on Mon, 20 Feb 2012 13:46:11 -0500 by phpDocumentor 1.4.1