Back to index

php5  5.3.10
spl_functions.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Marcus Boerger <helly@php.net>                              |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: spl_functions.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifdef HAVE_CONFIG_H
00022        #include "config.h"
00023 #endif
00024 
00025 #include "php.h"
00026 #include "php_ini.h"
00027 #include "ext/standard/info.h"
00028 #include "php_spl.h"
00029 
00030 /* {{{ spl_register_interface */
00031 void spl_register_interface(zend_class_entry ** ppce, char * class_name, const zend_function_entry * functions TSRMLS_DC)
00032 {
00033        zend_class_entry ce;
00034        
00035        INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), functions);
00036        *ppce = zend_register_internal_interface(&ce TSRMLS_CC);
00037 }
00038 /* }}} */
00039 
00040 /* {{{ spl_register_std_class */
00041 PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, const zend_function_entry * function_list TSRMLS_DC)
00042 {
00043        zend_class_entry ce;
00044        
00045        INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
00046        *ppce = zend_register_internal_class(&ce TSRMLS_CC);
00047 
00048        /* entries changed by initialize */
00049        if (obj_ctor) {
00050               (*ppce)->create_object = obj_ctor;
00051        }
00052 }
00053 /* }}} */
00054 
00055 /* {{{ spl_register_sub_class */
00056 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)
00057 {
00058        zend_class_entry ce;
00059        
00060        INIT_CLASS_ENTRY_EX(ce, class_name, strlen(class_name), function_list);
00061        *ppce = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC);
00062 
00063        /* entries changed by initialize */
00064        if (obj_ctor) {
00065               (*ppce)->create_object = obj_ctor;
00066        } else {
00067               (*ppce)->create_object = parent_ce->create_object;
00068        }
00069 }
00070 /* }}} */
00071 
00072 /* {{{ spl_register_property */
00073 void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC)
00074 {
00075        zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags TSRMLS_CC);
00076 }
00077 /* }}} */
00078 
00079 /* {{{ spl_add_class_name */
00080 void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
00081 {
00082        if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
00083               size_t len = pce->name_length;
00084               zval *tmp;
00085 
00086               if (zend_hash_find(Z_ARRVAL_P(list), pce->name, len+1, (void*)&tmp) == FAILURE) {
00087                      MAKE_STD_ZVAL(tmp);
00088                      ZVAL_STRINGL(tmp, pce->name, pce->name_length, 1);
00089                      zend_hash_add(Z_ARRVAL_P(list), pce->name, len+1, &tmp, sizeof(zval *), NULL);
00090               }
00091        }
00092 }
00093 /* }}} */
00094 
00095 /* {{{ spl_add_interfaces */
00096 void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
00097 {
00098        zend_uint num_interfaces;
00099 
00100        for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
00101               spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags TSRMLS_CC);
00102        }
00103 }
00104 /* }}} */
00105 
00106 /* {{{ spl_add_classes */
00107 int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
00108 {
00109        if (!pce) {
00110               return 0;
00111        }
00112        spl_add_class_name(list, pce, allow, ce_flags TSRMLS_CC);
00113        if (sub) {
00114               spl_add_interfaces(list, pce, allow, ce_flags TSRMLS_CC);
00115               while (pce->parent) {
00116                      pce = pce->parent;
00117                      spl_add_classes(pce, list, sub, allow, ce_flags TSRMLS_CC);
00118               }
00119        }
00120        return 0;
00121 }
00122 /* }}} */
00123 
00124 char * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len, int *name_len TSRMLS_DC) /* {{{ */
00125 {
00126        char *rv;
00127 
00128        zend_mangle_property_name(&rv, name_len, ce->name, ce->name_length, prop_name, prop_len, 0);
00129 
00130        return rv;
00131 }
00132 /* }}} */
00133 
00134 /*
00135  * Local variables:
00136  * tab-width: 4
00137  * c-basic-offset: 4
00138  * End:
00139  * vim600: fdm=marker
00140  * vim: noet sw=4 ts=4
00141  */