Source for file FileGetProxy.php

Documentation is available at FileGetProxy.php

  1. <?php
  2. /**
  3. * Class Proxy file when request is a get
  4. *
  5. * PHP versions 5
  6. @category  PHP
  7. @package   GeoPrisma
  8. @author    Julien-Samuel Lacroix
  9. @copyright 2010, Mapgears
  10. @license   http://www.geoprisma.org/license BSD License
  11. @link      http://www.geoprisma.org
  12. */
  13.  
  14. /**
  15. * Class Proxy file when request is a get
  16. @category   PHP
  17. @package    GeoPrisma
  18. @subpackage FileProxy
  19. @author     Julien-Samuel Lacroix
  20. */ 
  21. {
  22.  
  23.     private $m_objArrayAvailableLayers array();
  24.     private $m_objArrayAvailableResources array();
  25.  
  26.     /**
  27.     * Foward the call end return the result
  28.     * 
  29.     * @return void 
  30.     */
  31.     public function process()
  32.     {
  33.         $strFilePath $this->getLayer();
  34.  
  35.         $objFileTree new org_geoprisma_proxy_file_FileTree($this->getService()->getSource());
  36.  
  37.         echo $objFileTree->get($strFilePath$this->m_objArrayAvailableLayers$this->m_objArrayAvailableResources);
  38.     }
  39.     
  40.     /**
  41.     * Retourne le nom de l'action réaliser par le proxy (Create - Read - Update - Delete)
  42.     *                                   
  43.     * @return string 
  44.     */
  45.     public function getAction()
  46.     {
  47.         return self::CRUD_READ;    
  48.     }
  49.  
  50.     /**
  51.     * Retourne la liste de layer accèder par la query
  52.     * 
  53.     * @return ArrayObject 
  54.     */
  55.     private function getInlineLayers()
  56.     {
  57.         $objArrayLayers array();
  58.  
  59.         $strFilePath $this->getLayer();
  60.  
  61.         $objFileTree new org_geoprisma_proxy_file_FileTree(
  62.             $this->getService()->getSource()
  63.         );
  64.         $objArrayLayers $objFileTree->getFileList($strFilePath);
  65.  
  66.         return new ArrayObject($objArrayLayers);  
  67.     }
  68.  
  69.     /**
  70.     * Returns an array of org_geoprisma_resource_Resource objects being accessed
  71.     *     by the query.
  72.     * 
  73.     * @param org_geoprisma_config_Config &$pobjConfig The config object
  74.     * @param array                       $pobjRequest The request array that
  75.     *                                                  contains the 'osmservice'
  76.     *                                                  and 'osmresource'
  77.     *                                                  parameters.  Defaults to
  78.     *                                                  $_REQUEST.
  79.     *
  80.     * @return array 
  81.     */
  82.     public function getResourcesFromRequest(&$pobjConfig$pobjRequest=null)
  83.     {
  84.         $objRequest ($pobjRequest$pobjRequest $_REQUEST;
  85.  
  86.         if (!isset($objRequest['osmservice'])) 
  87.         {
  88.             throw new Exception("osmservice param is missing");
  89.         }
  90.  
  91.         // In the case of a get, we need to work with all the resources
  92.         // available for this service
  93.         $objArrayResource Array();
  94.         
  95.         $objService $this->getService();
  96.         $objConfigResources $pobjConfig->getResources();
  97.         foreach ($objConfigResources as $objResource)
  98.         {
  99.             if ($objResource->getDatastore($objService&& org_geoprisma_acl_ACLFactory::getACL()->isAuthorized($objResource$this->getAction())) 
  100.             {
  101.                 $objArrayResource[$objResource;
  102.             }
  103.         }
  104.  
  105.         return $objArrayResource;
  106.     }
  107.  
  108.     /**
  109.     * Validate the 'layers' being accessed by the query.  Each layer must be
  110.     *     present in one of the specified resource datastore using a specified
  111.     *     service.
  112.     * 
  113.     * @param org_geoprisma_service_Service $pobjService        The service to
  114.     *                                                           use for
  115.     *                                                           validation.
  116.     *                                                           Defaults to
  117.     *                                                           the proxy
  118.     *                                                           service.
  119.     * @param ArrayObject                   $pobjArrayResources ArrayObject of
  120.     *                                                           resource objects.
  121.     *                                                           Defaults to the
  122.     *                                                           proxy resources.
  123.     * @param ArrayObject                   $pobjArrayLayers    ArrayObject of
  124.     *                                                           layers to
  125.     *                                                           validate.
  126.     *                                                           Defaults to the
  127.     *                                                           layers returned
  128.     *                                                           by the proxy
  129.     *                                                           'getLayers'
  130.     *                                                           method.
  131.     *
  132.     * @return void 
  133.     */
  134.     public function validateLayersFromRequest(
  135.         $pobjService=null,
  136.         $pobjArrayResources=null,
  137.         $pobjArrayLayers=null
  138.     {
  139.         $objService ($pobjService === null$this->getService($pobjService;
  140.         $objArrayResources ($pobjArrayResources === null$this->getResources($pobjArrayResources;
  141.         $objArrayLayers ($pobjArrayLayers === null$this->getInlineLayers($pobjArrayLayers;
  142.         $strFilePath $this->getLayer();
  143.         if (substr($strFilePath-1!= '/' && strlen($strFilePath0
  144.         {
  145.             $strFilePath .= '/';
  146.         }
  147.  
  148.         $bAllAuthorized true;
  149.         foreach ($objArrayLayers as $strLayer
  150.         {
  151.             $bIsAuthorized false;
  152.             foreach ($objArrayResources as $objResource
  153.             {
  154.                 $objDatastore $objResource->getDatastore($objService);
  155.                 if (self::isAuthorizedLayer($objDatastore$strFilePath.$strLayer)) 
  156.                 {
  157.                     $this->m_objArrayAvailableLayers[$strLayer;
  158.                     $this->m_objArrayAvailableResources[$strLayer$objResource->getName();
  159.                     break;
  160.                 }
  161.             }
  162.         }
  163.  
  164.         if (count($this->m_objArrayAvailableLayers<= 0
  165.         {
  166.             throw new Exception('Not Authorized by Datastore layer');    
  167.         }
  168.     }
  169.  
  170.  
  171.     /**
  172.     * Validate if the layer is accessible in this datastore.
  173.     * 
  174.     * @param org_geoprisma_datastore_Datastore $pobjDatastore Datastore
  175.     * @param String                            $pstrLayer     Layer name
  176.     *
  177.     * @return Boolean 
  178.     */
  179.     private static function isAuthorizedLayer($pobjDatastore$pstrLayer)
  180.     {
  181.         $objArrayDSLayers $pobjDatastore->getLayers();
  182.  
  183.         $bAuthorized false;
  184.         foreach ($objArrayDSLayers as $strDSLayer)
  185.         {
  186.             if (substr($strDSLayer-1== '/'
  187.             {
  188.                 $strDSLayer substr($strDSLayer0-1);
  189.             }
  190.  
  191.             $objArrayDSPath explode('/'$strDSLayer);
  192.             $objArrayLayerPath explode('/'$pstrLayer);
  193.             $iNumDSPathNode count($objArrayDSPath);
  194.             $iNumLayerPathNode count($objArrayLayerPath);
  195.             $iNumPathNode min($iNumDSPathNode$iNumLayerPathNode);
  196.             for ($iIter=0$iIter<$iNumPathNode$iIter++)
  197.             {
  198.                 if ($objArrayDSPath[$iIter!= $objArrayLayerPath[$iIter]
  199.                 {
  200.                     break;
  201.                 }
  202.  
  203.                 if (($iIter+1>= $iNumPathNode
  204.                 {
  205.                     $bAuthorized true;
  206.                 }
  207.             }
  208.  
  209.             if ($bAuthorized
  210.             {
  211.                 break;
  212.             }
  213.         }
  214.  
  215.         return $bAuthorized;
  216.     }
  217. }
  218.  
  219. ?>

Documentation generated on Thu, 19 Jan 2012 00:08:31 +0400 by phpDocumentor 1.4.1