1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
|
/**********************************************************************
* $Id: php_mapscript.c 9765 2010-01-28 15:32:10Z aboudreault $
*
* Project: MapServer
* Purpose: PHP/MapScript extension for MapServer. External interface
* functions
* Author: Daniel Morissette, DM Solutions Group (dmorissette@dmsolutions.ca)
* Alan Boudreault, Mapgears
*
**********************************************************************
* Copyright (c) 2000-2010, Daniel Morissette, DM Solutions Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of this Software or works derived from this Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
**********************************************************************/
#include "php_mapscript.h"
zend_class_entry *mapscript_ce_class;
zend_object_handlers mapscript_class_object_handlers;
ZEND_BEGIN_ARG_INFO_EX(class___construct_args, 0, 0, 1)
ZEND_ARG_OBJ_INFO(0, layer, layerObj, 0)
ZEND_ARG_OBJ_INFO(0, class, classObj, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class___get_args, 0, 0, 1)
ZEND_ARG_INFO(0, property)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class___set_args, 0, 0, 2)
ZEND_ARG_INFO(0, property)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_updateFromString_args, 0, 0, 1)
ZEND_ARG_INFO(0, snippet)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_setExpression_args, 0, 0, 1)
ZEND_ARG_INFO(0, expression)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_setText_args, 0, 0, 1)
ZEND_ARG_INFO(0, text)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_getStyle_args, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_moveStyleUp_args, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_moveStyleDown_args, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_deleteStyle_args, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_getMetaData_args, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_setMetaData_args, 0, 0, 2)
ZEND_ARG_INFO(0, name)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_removeMetaData_args, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_createLegendIcon_args, 0, 0, 2)
ZEND_ARG_INFO(0, width)
ZEND_ARG_INFO(0, height)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(class_drawLegendIcon_args, 0, 0, 5)
ZEND_ARG_INFO(0, width)
ZEND_ARG_INFO(0, height)
ZEND_ARG_OBJ_INFO(0, image, imageObj, 0)
ZEND_ARG_INFO(0, dstX)
ZEND_ARG_INFO(0, dstY)
ZEND_END_ARG_INFO()
/* {{{ proto void __construct(layerObj layer [, classObj class])
Create a new class instance in the specified layer.. */
PHP_METHOD(classObj, __construct)
{
zval *zobj = getThis();
zval *zlayer, *zclass = NULL;
classObj *class;
php_layer_object *php_layer;
php_class_object *php_class, *php_class2;
parent_object parent;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O",
&zlayer, mapscript_ce_layer,
&zclass, mapscript_ce_class) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
php_layer = (php_layer_object *) zend_object_store_get_object(zlayer TSRMLS_CC);
if (zclass)
php_class2 = (php_class_object *) zend_object_store_get_object(zclass TSRMLS_CC);
if ((class = classObj_new(php_layer->layer, (zclass ? php_class2->class:NULL))) == NULL)
{
mapscript_throw_mapserver_exception("" TSRMLS_CC);
return;
}
php_class->class = class;
MAPSCRIPT_MAKE_PARENT(zlayer,NULL);
php_class->parent = parent;
MAPSCRIPT_ADDREF(parent.val);
}
/* }}} */
PHP_METHOD(classObj, __get)
{
char *property;
long property_len;
zval *zobj = getThis();
php_class_object *php_class;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&property, &property_len) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
IF_GET_STRING("name", php_class->class->name)
else IF_GET_STRING("title", php_class->class->title)
else IF_GET_LONG("type", php_class->class->type)
else IF_GET_LONG("status", php_class->class->status)
else IF_GET_DOUBLE("minscaledenom", php_class->class->minscaledenom)
else IF_GET_DOUBLE("maxscaledenom", php_class->class->maxscaledenom)
else IF_GET_LONG("minfeaturesize", php_class->class->minfeaturesize)
else IF_GET_STRING("template", php_class->class->template)
else IF_GET_STRING("keyimage", php_class->class->keyimage)
else IF_GET_STRING("group", php_class->class->group)
else IF_GET_LONG("numstyles", php_class->class->numstyles)
else IF_GET_OBJECT("label", mapscript_ce_label, php_class->label, &php_class->class->label)
else IF_GET_OBJECT("metadata", mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata)
else
{
mapscript_throw_exception("Property '%s' does not exist in this object." TSRMLS_CC, property);
}
}
PHP_METHOD(classObj, __set)
{
char *property;
long property_len;
zval *value;
zval *zobj = getThis();
php_class_object *php_class;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz",
&property, &property_len, &value) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
IF_SET_STRING("name", php_class->class->name, value)
else IF_SET_STRING("title", php_class->class->title, value)
else IF_SET_LONG("type", php_class->class->type, value)
else IF_SET_LONG("status", php_class->class->status, value)
else IF_SET_DOUBLE("minscaledenom", php_class->class->minscaledenom, value)
else IF_SET_DOUBLE("maxscaledenom", php_class->class->maxscaledenom, value)
else IF_SET_LONG("minfeaturesize", php_class->class->minfeaturesize, value)
else IF_SET_STRING("template", php_class->class->template, value)
else IF_SET_STRING("keyimage", php_class->class->keyimage, value)
else IF_SET_STRING("group", php_class->class->group, value)
else if ( (STRING_EQUAL("label", property)) ||
(STRING_EQUAL("metadata", property)))
{
mapscript_throw_exception("Property '%s' is an object and can only be modified through its accessors." TSRMLS_CC, property);
}
else if (STRING_EQUAL("numstyles", property))
{
mapscript_throw_exception("Property '%s' is read-only and cannot be set." TSRMLS_CC, property);
}
else
{
mapscript_throw_exception("Property '%s' does not exist in this object." TSRMLS_CC, property);
}
}
/* {{{ proto int updateFromString(string snippet)
Update a class from a string snippet. Returns MS_SUCCESS/MS_FAILURE */
PHP_METHOD(classObj, updateFromString)
{
char *snippet;
long snippet_len;
zval *zobj = getThis();
php_class_object *php_class;
int status = MS_FAILURE;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&snippet, &snippet_len) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
status = classObj_updateFromString(php_class->class, snippet);
if (status != MS_SUCCESS)
{
mapscript_throw_mapserver_exception("" TSRMLS_CC);
return;
}
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto int setExpression(string exression)
Set the expression string for a class object. */
PHP_METHOD(classObj, setExpression)
{
char *expression;
long expression_len;
zval *zobj = getThis();
php_class_object *php_class;
int status = MS_FAILURE;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&expression, &expression_len) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
status = classObj_setExpression(php_class->class, expression);
if (status != MS_SUCCESS)
{
mapscript_throw_mapserver_exception("" TSRMLS_CC);
return;
}
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto string getExpressionString()
Get the expression string for a class object. */
PHP_METHOD(classObj, getExpressionString)
{
zval *zobj = getThis();
php_class_object *php_class;
char *value = NULL;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters_none() == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
value = classObj_getExpressionString(php_class->class);
if (value == NULL)
RETURN_STRING("", 1);
RETVAL_STRING(value, 1);
free(value);
}
/* }}} */
/* {{{ proto int setText(string text)
Set the text string for a class object. */
PHP_METHOD(classObj, setText)
{
char *text;
long text_len;
zval *zobj = getThis();
php_class_object *php_class;
php_layer_object *php_layer;
int status = MS_FAILURE;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&text, &text_len) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
php_layer = (php_layer_object *) zend_object_store_get_object(php_class->parent.val TSRMLS_CC);
status = classObj_setText(php_class->class, php_layer->layer, text);
if (status != MS_SUCCESS)
{
mapscript_throw_mapserver_exception("" TSRMLS_CC);
return;
}
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto string getTextString()
Get the text string for a class object. */
PHP_METHOD(classObj, getTextString)
{
zval *zobj = getThis();
php_class_object *php_class;
char *value = NULL;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters_none() == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
value = classObj_getTextString(php_class->class);
if (value == NULL)
RETURN_STRING("", 1);
RETVAL_STRING(value, 1);
free(value);
}
/* }}} */
/* {{{ proto int getstyle(int index)
return the style object. */
PHP_METHOD(classObj, getStyle)
{
long index;
zval *zobj = getThis();
php_class_object *php_class;
styleObj *style = NULL;
parent_object parent;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
&index) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
if (index < 0 || index >= php_class->class->numstyles)
{
mapscript_throw_exception("Invalid style index." TSRMLS_CC);
return;
}
style = php_class->class->styles[index];
MAPSCRIPT_MAKE_PARENT(zobj, NULL);
mapscript_create_style(style, parent, return_value TSRMLS_CC);
}
/* }}} */
/* {{{ proto int moveStyleUp(int index) The style specified by the
style index will be moved up into the array of classes. Returns MS_SUCCESS
or MS_FAILURE. ex class->movestyleup(1) will have the effect of moving
style 1 up to position 0, and the style at position 0 will be moved to
position 1. */
PHP_METHOD(classObj, moveStyleUp)
{
long index;
zval *zobj = getThis();
php_class_object *php_class;
int status = MS_FAILURE;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
&index) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
status = classObj_moveStyleUp(php_class->class, index);
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto int moveStyleDown(int index) The style specified by the
style index will be moved down into the array of classes. Returns
MS_SUCCESS or MS_FAILURE. ex class->movestyledown(0) will have the
effect of moving style 0 up to position 1, and the style at position 1
will be moved to position 0. */
PHP_METHOD(classObj, moveStyleDown)
{
long index;
zval *zobj = getThis();
php_class_object *php_class;
int status = MS_FAILURE;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
&index) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
status = classObj_moveStyleDown(php_class->class, index);
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto int deleteStyle(int index) Delete the style specified
by the style index. If there are any style that follow the deleted
style, their index will decrease by 1. */
PHP_METHOD(classObj, deleteStyle)
{
long index;
zval *zobj = getThis();
php_class_object *php_class;
int status = MS_FAILURE;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",
&index) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
status = classObj_deleteStyle(php_class->class, index);
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto string getMetaData(string name)
Return MetaData entry by name, or empty string if not found. */
PHP_METHOD(classObj, getMetaData)
{
zval *zname;
zval *zobj = getThis();
php_class_object *php_class;
zval *retval;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
&zname) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
CHECK_OBJECT(mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata);
MAPSCRIPT_CALL_METHOD_1(php_class->metadata, "get", retval, zname);
RETURN_STRING(Z_STRVAL_P(retval),1);
}
/* }}} */
/* {{{ proto int setMetaData(string name, string value)
Set MetaData entry by name. Returns MS_SUCCESS/MS_FAILURE */
PHP_METHOD(classObj, setMetaData)
{
zval *zname, *zvalue;
zval *zobj = getThis();
php_class_object *php_class;
zval *retval;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
&zname, &zvalue) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
CHECK_OBJECT(mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata);
MAPSCRIPT_CALL_METHOD_2(php_class->metadata, "set", retval, zname, zvalue);
RETURN_LONG(Z_LVAL_P(retval));
}
/* }}} */
/* {{{ proto int removeMetaData(string name)
Remove MetaData entry by name. Returns MS_SUCCESS/MS_FAILURE */
PHP_METHOD(classObj, removeMetaData)
{
zval *zname;
zval *zobj = getThis();
php_class_object *php_class;
zval *retval;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
&zname) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
CHECK_OBJECT(mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata);
MAPSCRIPT_CALL_METHOD_1(php_class->metadata, "remove", retval, zname);
RETURN_LONG(Z_LVAL_P(retval));
}
/* }}} */
/* {{{ proto imageObj createLegendIcon(int width, int height)
Return the legend icon. */
PHP_METHOD(classObj, createLegendIcon)
{
zval *zobj = getThis();
long width, height;
imageObj *image = NULL;
php_class_object *php_class;
php_layer_object *php_layer;
php_map_object *php_map;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll",
&width, &height) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
php_layer = (php_layer_object *) zend_object_store_get_object(php_class->parent.val TSRMLS_CC);
if (!php_layer->parent.val)
{
mapscript_throw_exception("No map object associated with this class object." TSRMLS_CC);
return;
}
php_map = (php_map_object *) zend_object_store_get_object(php_layer->parent.val TSRMLS_CC);
if ((image = classObj_createLegendIcon(php_class->class,
php_map->map,
php_layer->layer,
width, height)) == NULL)
{
mapscript_throw_mapserver_exception("" TSRMLS_CC);
return;
}
/* Return an image object */
mapscript_create_image(image, return_value TSRMLS_CC);
}
/* }}} */
/* {{{ proto int drawLegendIcon(int width, int height, imageObj image, int dstX, int dstY)
set the lengend icon in img. */
PHP_METHOD(classObj, drawLegendIcon)
{
zval *zobj = getThis();
zval *zimage;
long width, height, dstX, dstY;
int status = MS_FAILURE;
php_class_object *php_class;
php_image_object *php_image;
php_layer_object *php_layer;
php_map_object *php_map;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llOll",
&width, &height,
&zimage, mapscript_ce_image,
&dstX, &dstY) == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
php_image = (php_image_object *) zend_object_store_get_object(zimage TSRMLS_CC);
php_layer = (php_layer_object *) zend_object_store_get_object(php_class->parent.val TSRMLS_CC);
if (!php_layer->parent.val)
{
mapscript_throw_exception("No map object associated with this class object." TSRMLS_CC);
return;
}
php_map = (php_map_object *) zend_object_store_get_object(php_layer->parent.val TSRMLS_CC);
if (!MS_RENDERER_PLUGIN(php_image->image->format))
{
mapscript_report_mapserver_error(E_WARNING TSRMLS_CC);
mapscript_report_php_error(E_WARNING, "DrawLegendicon function is only available for renderer plugin drivers" TSRMLS_CC);
RETURN_LONG(MS_FAILURE);
}
if ((status = classObj_drawLegendIcon(php_class->class,
php_map->map,
php_layer->layer,
width, height,
php_image->image,
dstX, dstY)) != MS_SUCCESS)
{
mapscript_report_mapserver_error(E_WARNING TSRMLS_CC);
}
RETURN_LONG(status);
}
/* }}} */
/* {{{ proto string free()
Free the object */
PHP_METHOD(classObj, free)
{
zval *zobj = getThis();
php_class_object *php_class;
PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
if (zend_parse_parameters_none() == FAILURE) {
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
return;
}
PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
MAPSCRIPT_DELREF(php_class->label);
MAPSCRIPT_DELREF(php_class->metadata);
}
/* }}} */
zend_function_entry class_functions[] = {
PHP_ME(classObj, __construct, class___construct_args, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(classObj, __get, class___get_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, __set, class___set_args, ZEND_ACC_PUBLIC)
PHP_MALIAS(classObj, set, __set, NULL, ZEND_ACC_PUBLIC)
PHP_ME(classObj, updateFromString, class_updateFromString_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, setExpression, class_setExpression_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, getExpressionString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(classObj, setText, class_setText_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, getTextString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(classObj, getStyle, class_getStyle_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, moveStyleUp, class_moveStyleUp_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, moveStyleDown, class_moveStyleDown_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, deleteStyle, class_deleteStyle_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, getMetaData, class_getMetaData_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, setMetaData, class_setMetaData_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, removeMetaData, class_removeMetaData_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, createLegendIcon, class_createLegendIcon_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, drawLegendIcon, class_drawLegendIcon_args, ZEND_ACC_PUBLIC)
PHP_ME(classObj, free, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
void mapscript_create_class(classObj *class, parent_object parent, zval *return_value TSRMLS_DC)
{
php_class_object * php_class;
object_init_ex(return_value, mapscript_ce_class);
php_class = (php_class_object *)zend_object_store_get_object(return_value TSRMLS_CC);
php_class->class = class;
php_class->parent = parent;
MAPSCRIPT_ADDREF(parent.val);
}
static void mapscript_class_object_destroy(void *object TSRMLS_DC)
{
php_class_object *php_class = (php_class_object *)object;
MAPSCRIPT_FREE_OBJECT(php_class);
MAPSCRIPT_FREE_PARENT(php_class->parent);
MAPSCRIPT_DELREF(php_class->label);
MAPSCRIPT_DELREF(php_class->metadata);
/* We don't need to free the classObj */
efree(object);
}
static zend_object_value mapscript_class_object_new_ex(zend_class_entry *ce, php_class_object **ptr TSRMLS_DC)
{
zend_object_value retval;
php_class_object *php_class;
MAPSCRIPT_ALLOC_OBJECT(php_class, php_class_object);
retval = mapscript_object_new_ex(&php_class->std, ce,
&mapscript_class_object_destroy,
&mapscript_class_object_handlers TSRMLS_CC);
if (ptr)
*ptr = php_class;
MAPSCRIPT_INIT_PARENT(php_class->parent);
php_class->label = NULL;
php_class->metadata = NULL;
return retval;
}
static zend_object_value mapscript_class_object_new(zend_class_entry *ce TSRMLS_DC)
{
return mapscript_class_object_new_ex(ce, NULL TSRMLS_CC);
}
static zend_object_value mapscript_class_object_clone(zval *zobj TSRMLS_DC)
{
php_class_object *php_class_old, *php_class_new;
php_layer_object *php_layer;
zend_object_value new_ov;
php_class_old = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
php_layer = (php_layer_object *) zend_object_store_get_object(php_class_old->parent.val TSRMLS_CC);
new_ov = mapscript_class_object_new_ex(mapscript_ce_class, &php_class_new TSRMLS_CC);
zend_objects_clone_members(&php_class_new->std, new_ov, &php_class_old->std, Z_OBJ_HANDLE_P(zobj) TSRMLS_CC);
php_class_new->class = classObj_clone(php_class_old->class, php_layer->layer);
return new_ov;
}
PHP_MINIT_FUNCTION(class)
{
zend_class_entry ce;
memcpy(&mapscript_class_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
mapscript_class_object_handlers.clone_obj = mapscript_class_object_clone;
MAPSCRIPT_REGISTER_CLASS("classObj",
class_functions,
mapscript_ce_class,
mapscript_class_object_new);
mapscript_ce_class->ce_flags |= ZEND_ACC_FINAL_CLASS;
return SUCCESS;
}
|