[mapserver-commits] r8134 - in trunk/mapserver: . mapscript/php3

svn at osgeo.org svn at osgeo.org
Fri Nov 28 15:21:03 EST 2008


Author: aboudreault
Date: 2008-11-28 15:21:03 -0500 (Fri, 28 Nov 2008)
New Revision: 8134

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapscript/php3/mapscript_i.c
   trunk/mapserver/mapscript/php3/php_mapscript.c
   trunk/mapserver/mapscript/php3/php_mapscript.h
Log:
Added removeLayer function to mapObj in PHP/MapScript. (#762)


Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-11-28 18:56:28 UTC (rev 8133)
+++ trunk/mapserver/HISTORY.TXT	2008-11-28 20:21:03 UTC (rev 8134)
@@ -12,6 +12,8 @@
 Current Version (5.3-dev, SVN trunk):
 ------------------------------------
 
+- Added removeLayer function to mapObj in PHP/MapScript. (#762)
+
 - Exposed PIXELS value via URL configuration
 
 - Add Support for SLD TextSymbolizer HALO and ANGLE (#2806)

Modified: trunk/mapserver/mapscript/php3/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php3/mapscript_i.c	2008-11-28 18:56:28 UTC (rev 8133)
+++ trunk/mapserver/mapscript/php3/mapscript_i.c	2008-11-28 20:21:03 UTC (rev 8134)
@@ -343,6 +343,11 @@
     return -1;
 }
 
+layerObj *mapObj_removeLayer(mapObj *self, int layerindex)
+{
+    return msRemoveLayer(self, layerindex);
+}
+
 /**********************************************************************
  * class extensions for layerObj, always within the context of a map
  **********************************************************************/
@@ -363,8 +368,18 @@
   }
 
 void layerObj_destroy(layerObj *self) {
-    return; // map deconstructor takes care of it
-  }
+   /* if the layer has a parent_map, let's the map object destroy it */
+   if ((self->map == NULL) && (self->refcount == 1)) {
+      /* if there is no other PHP Object that use this C layer object, delete it */
+         freeLayer(self);
+         free(self);
+         self = NULL;
+   } else 
+   {
+      MS_REFCNT_DECR(self);  
+   }
+   return;
+}
 
 int layerObj_open(layerObj *self) {
     return msLayerOpen(self);

Modified: trunk/mapserver/mapscript/php3/php_mapscript.c
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.c	2008-11-28 18:56:28 UTC (rev 8133)
+++ trunk/mapserver/mapscript/php3/php_mapscript.c	2008-11-28 20:21:03 UTC (rev 8134)
@@ -75,6 +75,7 @@
 static void php_ms_free_map(zend_rsrc_list_entry *rsrc TSRMLS_DC);
 
 static void php_ms_free_image(zend_rsrc_list_entry *rsrc TSRMLS_DC);
+DLEXPORT void php3_ms_free_layer(layerObj *pLayer);
 DLEXPORT void php3_ms_free_point(pointObj *pPoint);
 DLEXPORT void php3_ms_free_line(lineObj *pLine);
 DLEXPORT void php3_ms_free_shape(shapeObj *pShape);
@@ -169,6 +170,7 @@
 DLEXPORT void php3_ms_map_OWSDispatch(INTERNAL_FUNCTION_PARAMETERS);
 
 DLEXPORT void php3_ms_map_insertLayer(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_map_removeLayer(INTERNAL_FUNCTION_PARAMETERS);
 
 DLEXPORT void php3_ms_img_saveImage(INTERNAL_FUNCTION_PARAMETERS);
 DLEXPORT void php3_ms_img_saveWebImage(INTERNAL_FUNCTION_PARAMETERS);
@@ -707,6 +709,7 @@
     {"loadowsparameters",  php3_ms_map_loadOWSParameters,       NULL},
     {"owsdispatch",     php3_ms_map_OWSDispatch,        NULL},
     {"insertlayer",     php3_ms_map_insertLayer,        NULL},
+    {"removelayer",     php3_ms_map_removeLayer,        NULL},
     {NULL, NULL, NULL}
 };
 
@@ -1010,10 +1013,9 @@
     PHPMS_GLOBAL(le_msimg)  = 
         zend_register_list_destructors_ex(php_ms_free_image, NULL,
                                           "imageObj", module_number);
-    PHPMS_GLOBAL(le_mslayer)= 
-        zend_register_list_destructors_ex(NULL, NULL,
-                                          "layerObj", module_number);
 
+    PHPMS_GLOBAL(le_mslayer)= register_list_destructors(php3_ms_free_layer,
+                                                            NULL);
     PHPMS_GLOBAL(le_msclass)= register_list_destructors(php3_ms_free_stub,
                                                         NULL);
     PHPMS_GLOBAL(le_mslabel)= register_list_destructors(php3_ms_free_stub,
@@ -1410,6 +1412,11 @@
     msFreeImage(image);
 }
 
+DLEXPORT void php3_ms_free_layer(layerObj *pLayer) 
+{
+    layerObj_destroy(pLayer);
+}
+
 DLEXPORT void php3_ms_free_rect(rectObj *pRect) 
 {
     rectObj_destroy(pRect);
@@ -6043,8 +6050,7 @@
                                          list TSRMLS_CC);
     poLayer = (layerObj *)_phpms_fetch_handle(pLyr, 
                                               PHPMS_GLOBAL(le_mslayer),
-                                              list TSRMLS_CC);
-
+                                              list TSRMLS_CC); 
     if (self == NULL || poLayer == NULL ||
         (iReturn =  mapObj_insertLayer(self, poLayer, nLyrIndex) ) < 0)
     {
@@ -6061,10 +6067,55 @@
 }
 /* }}} */
 
+/**********************************************************************
+ *                        map->removelayer()
+ *
+ * Remove layer from map object
+ **********************************************************************/
+
+/* {{{ proto int map.removeLayer(int layer_index)
+   Returns layerObj removed on sucess, else null. */
+ 
+DLEXPORT void php3_ms_map_removeLayer(INTERNAL_FUNCTION_PARAMETERS)
+{ 
+    pval  *pThis;
+    long  layerIndex = 0;
+    mapObj *self=NULL;
+    layerObj *poLayer=NULL;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &layerIndex) 
+         == FAILURE))
+    {
+       return;
+    }
+
+    self = (mapObj *)_phpms_fetch_handle(pThis, PHPMS_GLOBAL(le_msmap), 
+                                         list TSRMLS_CC);
+    
+    if (self == NULL ||
+        (poLayer = mapObj_removeLayer(self, layerIndex)) == NULL)
+    {
+        _phpms_report_mapserver_error(E_ERROR);
+    }
+
+     /* Update mapObj members */
+    _phpms_set_property_long(pThis, "numlayers",
+                             self->numlayers, E_ERROR TSRMLS_CC); 
+
+     /* Return layer object */
+    _phpms_build_layer_object(poLayer, (int)NULL, list, return_value TSRMLS_CC);
+    
+}
 /* }}} */
 
+/* }}} */
 
 
+
 /*=====================================================================
  *                 PHP function wrappers - image class
  *====================================================================*/
@@ -6500,12 +6551,10 @@
     _phpms_object_init(return_value, layer_id, php_layer_class_functions,
                        PHP4_CLASS_ENTRY(layer_class_entry_ptr) TSRMLS_CC);
 
-#ifdef PHP4
-    zend_list_addref(parent_map_id);
+    if (parent_map_id != (int)NULL)
+       zend_list_addref(parent_map_id);
     add_property_resource(return_value, "_map_handle_", parent_map_id);
-#else
-    add_property_long(return_value, "_map_handle_", parent_map_id);
-#endif
+    MS_REFCNT_INCR(player);
 
     /* read-only properties */
     add_property_long(return_value,   "numclasses", player->numclasses);

Modified: trunk/mapserver/mapscript/php3/php_mapscript.h
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.h	2008-11-28 18:56:28 UTC (rev 8133)
+++ trunk/mapserver/mapscript/php3/php_mapscript.h	2008-11-28 20:21:03 UTC (rev 8134)
@@ -127,6 +127,7 @@
                                           char *wmtver_string);
 int             mapObj_OWSDispatch(mapObj *self, cgiRequestObj *req );
 int             mapObj_insertLayer(mapObj *self, layerObj *layer, int index);
+layerObj        *mapObj_removeLayer(mapObj *self, int layerindex);
 
 layerObj       *layerObj_new(mapObj *map);
 void            layerObj_destroy(layerObj* self);



More information about the mapserver-commits mailing list