spl_functions.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 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. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include "php.h"
  22. #include "php_ini.h"
  23. #include "ext/standard/info.h"
  24. #include "php_spl.h"
  25. /* {{{ spl_register_interface */
  26. void spl_register_interface(zend_class_entry ** ppce, char * class_name, const zend_function_entry * functions)
  27. {
  28. zend_class_entry ce;
  29. INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), functions);
  30. *ppce = zend_register_internal_interface(&ce);
  31. }
  32. /* }}} */
  33. /* {{{ spl_register_std_class */
  34. PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, const zend_function_entry * function_list)
  35. {
  36. zend_class_entry ce;
  37. INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
  38. *ppce = zend_register_internal_class(&ce);
  39. /* entries changed by initialize */
  40. if (obj_ctor) {
  41. (*ppce)->create_object = obj_ctor;
  42. }
  43. }
  44. /* }}} */
  45. /* {{{ spl_register_sub_class */
  46. 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)
  47. {
  48. zend_class_entry ce;
  49. INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
  50. *ppce = zend_register_internal_class_ex(&ce, parent_ce);
  51. /* entries changed by initialize */
  52. if (obj_ctor) {
  53. (*ppce)->create_object = obj_ctor;
  54. } else {
  55. (*ppce)->create_object = parent_ce->create_object;
  56. }
  57. }
  58. /* }}} */
  59. /* {{{ spl_register_property */
  60. void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags)
  61. {
  62. zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags);
  63. }
  64. /* }}} */
  65. /* {{{ spl_add_class_name */
  66. void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
  67. {
  68. if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
  69. zval *tmp;
  70. if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
  71. zval t;
  72. ZVAL_STR_COPY(&t, pce->name);
  73. zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
  74. }
  75. }
  76. }
  77. /* }}} */
  78. /* {{{ spl_add_interfaces */
  79. void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
  80. {
  81. uint32_t num_interfaces;
  82. for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
  83. spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
  84. }
  85. }
  86. /* }}} */
  87. /* {{{ spl_add_traits */
  88. void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
  89. {
  90. uint32_t num_traits;
  91. for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
  92. spl_add_class_name(list, pce->traits[num_traits], allow, ce_flags);
  93. }
  94. }
  95. /* }}} */
  96. /* {{{ spl_add_classes */
  97. int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags)
  98. {
  99. if (!pce) {
  100. return 0;
  101. }
  102. spl_add_class_name(list, pce, allow, ce_flags);
  103. if (sub) {
  104. spl_add_interfaces(list, pce, allow, ce_flags);
  105. while (pce->parent) {
  106. pce = pce->parent;
  107. spl_add_classes(pce, list, sub, allow, ce_flags);
  108. }
  109. }
  110. return 0;
  111. }
  112. /* }}} */
  113. zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
  114. {
  115. return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
  116. }
  117. /* }}} */
  118. /*
  119. * Local variables:
  120. * tab-width: 4
  121. * c-basic-offset: 4
  122. * End:
  123. * vim600: fdm=marker
  124. * vim: noet sw=4 ts=4
  125. */