Source for file HttpRequestProxy.php

Documentation is available at HttpRequestProxy.php

  1. <?php
  2. /**
  3. * Proxy of HttpRequest type
  4. *
  5. * PHP versions 5
  6. *
  7. @category  PHP
  8. @package   GeoPrisma
  9. @author    Frédérick Gagnon
  10. @copyright 2009, Boreal - Information Strategies
  11. @license   http://www.geoprisma.org/license BSD License
  12. @link      http://www.geoprisma.org
  13. */
  14.  
  15. /**
  16. * Proxy of HttpRequest type
  17. @category   PHP
  18. @package    GeoPrisma
  19. @subpackage Proxy
  20. @author     Frédérick Gagnon
  21. */     
  22. {
  23.     private $m_strRequestName null;
  24.     private $m_objArrayAvailableRequestsActions array();
  25.  
  26.     /**
  27.     * Creates a new instance of org_geoprisma_proxy_httprequest_HttpRequestProxy
  28.     *
  29.     * @param array $pobjService Service object
  30.     * @param array $pobjRequest Request array
  31.     *
  32.     * @return org_geoprisma_proxy_httprequest_HttpRequestProxy 
  33.     */
  34.     public function __construct($pobjService$pobjRequest=null)
  35.     {
  36.         $pobjRequest !is_null($pobjRequest$pobjRequest $_REQUEST;
  37.         
  38.         if (!isset($pobjRequest['REQUEST'])) 
  39.         {
  40.             throw new Exception("REQUEST param is missing");
  41.         }
  42.  
  43.         $this->m_strRequestName = (string)$pobjRequest['REQUEST'];
  44.  
  45.         foreach ($pobjService->m_objArrayCreateHttpRequests as $strAvailableRequest)
  46.         {
  47.             $this->m_objArrayAvailableRequestsActions[$strAvailableRequestself::CRUD_CREATE;
  48.         }
  49.  
  50.         foreach ($pobjService->m_objArrayReadHttpRequests as $strAvailableRequest)
  51.         {
  52.             $this->m_objArrayAvailableRequestsActions[$strAvailableRequestself::CRUD_READ;
  53.         }
  54.  
  55.         foreach ($pobjService->m_objArrayUpdateHttpRequests as $strAvailableRequest)
  56.         {
  57.             $this->m_objArrayAvailableRequestsActions[$strAvailableRequestself::CRUD_UPDATE;
  58.         }
  59.  
  60.         foreach ($pobjService->m_objArrayDeleteHttpRequests as $strAvailableRequest)
  61.         {
  62.             $this->m_objArrayAvailableRequestsActions[$strAvailableRequestself::CRUD_DELETE;
  63.         }
  64.  
  65.         if (empty($this->m_objArrayAvailableRequestsActions)) 
  66.         {
  67.             throw new Exception("Service has no available request");
  68.         }
  69.  
  70.         if (!isset($this->m_objArrayAvailableRequestsActions[$this->m_strRequestName])) 
  71.         {
  72.             throw new Exception("Request has no available action");
  73.         }
  74.  
  75.         parent::__construct($pobjService);
  76.     }
  77.     /**
  78.     * Returns the name of the action done by this proxy (Create / Read / Update / Delete)
  79.     *                                   
  80.     * @return string 
  81.     */
  82.     public function getAction()
  83.     {
  84.         return $this->m_objArrayAvailableRequestsActions[$this->m_strRequestName];
  85.     }
  86.  
  87.     /**
  88.     * Foward the call end return the result
  89.     * 
  90.     * @return void 
  91.     */
  92.     public function process()
  93.     {
  94.         $objArrayResources $this->getResources();
  95.         $objArrayLayers $objArrayResources[0]->getDatastore($this->getService())->getLayers();
  96.         $strAdditionalParams['REQUEST_DATA'$objArrayLayers[0];
  97.  
  98.         ob_start();
  99.         $objCurl curl_init();
  100.         curl_setopt($objCurlCURLOPT_URLself::addParam($this->getService()->getSource()$strAdditionalParams));
  101.         curl_setopt($objCurlCURLOPT_POSTtrue);
  102.         curl_setopt($objCurlCURLOPT_POSTFIELDSfile_get_contents('php://input'));
  103.         curl_setopt($objCurlCURLOPT_HTTPHEADERarray('Content-Type: application/x-www-form-urlencoded'));
  104.  
  105.         curl_exec($objCurl);
  106.  
  107.         $objArrayInfo curl_getinfo($objCurl);
  108.         curl_close($objCurl);
  109.  
  110.         header("Content-type: ".$objArrayInfo['content_type']);
  111.  
  112.         ob_end_flush();
  113.     }
  114.     
  115.     /**
  116.     * Returns the list of layers accessible by this proxy
  117.     *
  118.     * @return ArrayObject 
  119.     */
  120.     public function getLayers()
  121.     {
  122.         return new ArrayObject();
  123.     }
  124.  
  125.  
  126.     /**
  127.     * Add received GET parameters to an URL
  128.     *
  129.     * @param string $pstrUrl              Url
  130.     * @param array  $pstrAdditionalParams Params array
  131.     *
  132.     * @return string 
  133.     */
  134.     static public function addParam($pstrUrl$pstrAdditionalParams)
  135.     {
  136.         if (strpos($pstrUrl'?'=== false
  137.         {
  138.             return $pstrUrl."?".http_build_query(array_merge(self::getRequestParams()$pstrAdditionalParams));
  139.         }
  140.         else
  141.         {
  142.             return $pstrUrl."&".http_build_query(array_merge(self::getRequestParams()$pstrAdditionalParams));
  143.         }
  144.     }
  145. }
  146. ?>

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