Explorar o código

Completadas otras funciones de la api

Maximiliano Schvindt %!s(int64=7) %!d(string=hai) anos
pai
achega
ddbbe719b7
Modificáronse 1 ficheiros con 15 adicións e 58 borrados
  1. 15 58
      Services/GeoserverService.php

+ 15 - 58
Services/GeoserverService.php

@@ -83,16 +83,18 @@ class GeoserverService
 
     }
 
-    /* public function getLayers($workspace) 
+    public function getLayers($workspace) 
     {
 
         $nameWorkspace = "{$workspace}";
         $ch = curl_init();
 
-        curl_setopt($ch, CURLOPT_URL, "http://{$this->host}:{$this->port}/geoserver/rest/workspaces/{$nameWorkspace}/datastores/shapefiles/featuretypes.json");
+        $url = "{$this->getUrlRest()}/workspaces/{$workspace}/datastores/shapefiles/featuretypes.json";
+
+        curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
-        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}" . ":" . "{$this->pass}");
+        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");
 
         $headers = array();
         $headers[] = "Accept: application/json";
@@ -108,7 +110,7 @@ class GeoserverService
             return $data;
 
         return array();
-    } */
+    } 
 
     // ELIMINAMOS EL SHAPE - curl -v -u admin:geoserver -XDELETE "http://localhost:8080/geoserver/rest/layers/workspaceName:shapeName.json"
     // ELIMINAMOS EL REGISTRO EN DATASTORE - curl -v -u admin:geoserver -XDELETE "http://localhost:8080/geoserver/rest/workspaces/workspaceName/datastores/shapefiles/featuretypes/shapeName.json"
@@ -118,7 +120,6 @@ class GeoserverService
 
         $urlLayer = "{$this->getUrlRest()}/layers/{$workspace}:{$shape}.json";
         $urlWorkspace = "{$this->getUrlRest()}/workspaces/{$workspace}/datastores/shapefiles/featuretypes/{$shape}.json";
-        
 
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
@@ -135,36 +136,6 @@ class GeoserverService
         curl_close ($ch);
     }
 
-    /* public function createUser($user) 
-    {
-        
-        $nameUser = "user{$user->getId()}";
-        $passUser = $user->getGeoPass();
-        $ch = curl_init();
-
-        $url = "http://{$this->host}:{$this->port}/geoserver/rest/security/usergroup/default/users";
-        
-        curl_setopt($ch, CURLOPT_URL, $url);
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        curl_setopt($ch, CURLOPT_POSTFIELDS, "<user><userName>{$nameUser}</userName><password>{$passUser}</password><enabled>true</enabled></user>");
-        curl_setopt($ch, CURLOPT_POST, 1);
-        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}" . ":" . "{$this->pass}");
-
-        $headers = array();
-        $headers[] = "Content-Type: text/xml";
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-
-        $result = curl_exec($ch);
-        if (curl_errno($ch)) {echo 'Error:' . curl_error($ch);}
-        
-        $file = fopen(LOG_FILE,"a+");
-        fwrite($file,"CREATE USER: ".$url.PHP_EOL);
-        fwrite($file,"return - CREATE USER: ".$result.PHP_EOL);
-        fclose($file);
-
-        curl_close($ch);
-    } */
-
     public function putShape($rest, $data) 
     {
 
@@ -201,7 +172,7 @@ class GeoserverService
         return $url;
     }
 
-    /*
+    
     public function existResource($url) 
     {
 
@@ -210,7 +181,7 @@ class GeoserverService
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
-        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}" . ":" . "{$this->pass}");
+        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");
 
         $headers = array();
         $headers[] = "Accept: application/json";
@@ -230,14 +201,13 @@ class GeoserverService
 
     public function getLayerData($workspace, $shape) 
     {
-
-        $nameWorkspace = "{$workspace}";
+        $url = "{$this->getUrlRest()}/workspaces/{$workspace}/datastores/shapefiles/featuretypes/{$shape}.json";
         $ch = curl_init();
 
-        curl_setopt($ch, CURLOPT_URL, "http://{$this->host}:{$this->port}/geoserver/rest/workspaces/{$nameWorkspace}/datastores/shapefiles/featuretypes/{$shape}.json");
+        curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
-        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}" . ":" . "{$this->pass}");
+        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");
 
         $headers = array();
         $headers[] = "Accept: application/json";
@@ -260,16 +230,12 @@ class GeoserverService
 
         $ch = curl_init();
 
-        $url = "http://{$this->host}:{$this->port}/geoserver/{$workspace}/wms?".http_build_query($params);
-
-        $file = fopen(LOG_FILE,"a+");
-        fwrite($file,"GET FEATURE: ".$url.PHP_EOL);
-        fclose($file);
+        $url = "{$this->getUrlWms($workspace)}?".http_build_query($params);
 
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
-        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}" . ":" . "{$this->pass}");
+        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");
 
         $headers = array();
         $headers[] = "Accept: application/json";
@@ -287,26 +253,19 @@ class GeoserverService
         
     }
 
-    
-
     public function getImage($workspace, $params) 
     {
 
         $ch = curl_init();
 
-        $url = "http://{$this->host}:{$this->port}/geoserver/{$workspace}/wms?".http_build_query($params);
-
-        $file = fopen(LOG_FILE,"a+");
-        fwrite($file,"GET IMAGE: ".$url.PHP_EOL);
-        fclose($file);
+        $url = "{$this->getUrlWms($workspace)}?".http_build_query($params);
 
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
-        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}" . ":" . "{$this->pass}");
+        curl_setopt($ch, CURLOPT_USERPWD, "{$this->user}:{$this->pass}");
 
         $headers = array();
-        //$headers[] = "Accept: application/json";
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 
         $result = curl_exec($ch);
@@ -318,7 +277,5 @@ class GeoserverService
 
     }
 
-    */
-
 
 }