spl_functions.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Marcus Boerger <helly@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #include "php_ini.h"
  24. #include "ext/standard/info.h"
  25. #include "php_spl.h"
  26. /* {{{ spl_register_interface */
  27. void spl_register_interface(zend_class_entry ** ppce, char * class_name, const zend_function_entry * functions TSRMLS_DC)
  28. {
  29. zend_class_entry ce;
  30. INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), functions);
  31. *ppce = zend_register_internal_interface(&ce TSRMLS_CC);
  32. }
  33. /* }}} */
  34. /* {{{ spl_register_std_class */
  35. PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, const zend_function_entry * function_list TSRMLS_DC)
  36. {
  37. zend_class_entry ce;
  38. INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
  39. *ppce = zend_register_internal_class(&ce TSRMLS_CC);
  40. /* entries changed by initialize */
  41. if (obj_ctor) {
  42. (*ppce)->create_object = obj_ctor;
  43. }
  44. }
  45. /* }}} */
  46. /* {{{ spl_register_sub_class */
  47. PHPAPI void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, void *obj_ctor, const zend_function_entry * function_list TSRMLS_DC)
  48. {
  49. zend_class_entry ce;
  50. INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
  51. *ppce = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC);
  52. /* entries changed by initialize */
  53. if (obj_ctor) {
  54. (*ppce)->create_object = obj_ctor;
  55. } else {
  56. (*ppce)->create_object = parent_ce->create_object;
  57. }
  58. }
  59. /* }}} */
  60. /* {{{ spl_register_property */
  61. void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC)
  62. {
  63. zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags TSRMLS_CC);
  64. }
  65. /* }}} */
  66. /* {{{ spl_add_class_name */
  67. void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
  68. {
  69. if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
  70. size_t len = pce->name_length;
  71. zval *tmp;
  72. if (zend_hash_find(Z_ARRVAL_P(list), pce->name, len+1, (void*)&tmp) == FAILURE) {
  73. MAKE_STD_ZVAL(tmp);
  74. ZVAL_STRINGL(tmp, pce->name, pce->name_length, 1);
  75. zend_hash_add(Z_ARRVAL_P(list), pce->name, len+1, &tmp, sizeof(zval *), NULL);
  76. }
  77. }
  78. }
  79. /* }}} */
  80. /* {{{ spl_add_interfaces */
  81. void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
  82. {
  83. zend_uint num_interfaces;
  84. for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
  85. spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags TSRMLS_CC);
  86. }
  87. }
  88. /* }}} */
  89. /* {{{ spl_add_traits */
  90. void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
  91. {
  92. zend_uint num_traits;
  93. for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
  94. spl_add_class_name(list, pce->traits[num_traits], allow, ce_flags TSRMLS_CC);
  95. }
  96. }
  97. /* }}} */
  98. /* {{{ spl_add_classes */
  99. int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
  100. {
  101. if (!pce) {
  102. return 0;
  103. }
  104. spl_add_class_name(list, pce, allow, ce_flags TSRMLS_CC);
  105. if (sub) {
  106. spl_add_interfaces(list, pce, allow, ce_flags TSRMLS_CC);
  107. while (pce->parent) {
  108. pce = pce->parent;
  109. spl_add_classes(pce, list, sub, allow, ce_flags TSRMLS_CC);
  110. }
  111. }
  112. return 0;
  113. }
  114. /* }}} */
  115. char * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len, int *name_len TSRMLS_DC) /* {{{ */
  116. {
  117. char *rv;
  118. zend_mangle_property_name(&rv, name_len, ce->name, ce->name_length, prop_name, prop_len, 0);
  119. return rv;
  120. }
  121. /* }}} */
  122. /*
  123. * Local variables:
  124. * tab-width: 4
  125. * c-basic-offset: 4
  126. * End:
  127. * vim600: fdm=marker
  128. * vim: noet sw=4 ts=4
  129. */