spl_functions.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Marcus Boerger <helly@php.net> |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifdef HAVE_CONFIG_H
  17. #include "config.h"
  18. #endif
  19. #include "php.h"
  20. #include "php_ini.h"
  21. #include "ext/standard/info.h"
  22. #include "php_spl.h"
  23. /* {{{ spl_add_class_name */
  24. void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
  25. {
  26. if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
  27. zval *tmp;
  28. if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
  29. zval t;
  30. ZVAL_STR_COPY(&t, pce->name);
  31. zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
  32. }
  33. }
  34. }
  35. /* }}} */
  36. /* {{{ spl_add_interfaces */
  37. void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
  38. {
  39. uint32_t num_interfaces;
  40. if (pce->num_interfaces) {
  41. ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
  42. for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
  43. spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
  44. }
  45. }
  46. }
  47. /* }}} */
  48. /* {{{ spl_add_traits */
  49. void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
  50. {
  51. uint32_t num_traits;
  52. zend_class_entry *trait;
  53. for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
  54. trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
  55. pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
  56. ZEND_ASSERT(trait);
  57. spl_add_class_name(list, trait, allow, ce_flags);
  58. }
  59. }
  60. /* }}} */
  61. /* {{{ spl_add_classes */
  62. int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags)
  63. {
  64. if (!pce) {
  65. return 0;
  66. }
  67. spl_add_class_name(list, pce, allow, ce_flags);
  68. if (sub) {
  69. spl_add_interfaces(list, pce, allow, ce_flags);
  70. while (pce->parent) {
  71. pce = pce->parent;
  72. spl_add_classes(pce, list, sub, allow, ce_flags);
  73. }
  74. }
  75. return 0;
  76. }
  77. /* }}} */
  78. zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
  79. {
  80. return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
  81. }
  82. /* }}} */