ALLOC_HASHTABLE(custom_object->zo.properties); zend_hash_init(custom_object->zo.properties, 0, NULL, ZVAL_PTR_DTOR, 0); zend_hash_copy(custom_object->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &temp, sizeof(zval *)); #else object_properties_init(&custom_object->zo, class_type); #endif retval.handle = zend_objects_store_put(custom_object, NULL, php_<?php echo $class_name; ?> _free, NULL TSRMLS_CC); retval.handlers = zend_get_std_object_handlers(); custom_object->native_object = NULL; <?php if (!in_array("__construct", funcsOfClass($class_name, 1)) && has_all_pure_virtual_implemented($class_name)) { ?> #if PHP_VERSION_ID > 50399 MAKE_STD_ZVAL(temp); Z_TYPE_P(temp) = IS_OBJECT; Z_OBJVAL_P(temp) = retval; #endif custom_object->native_object = new <?php echo $class_name; ?> _php(); custom_object->native_object->phpObj = temp; #ifdef ZTS custom_object->native_object->TSRMLS_C = TSRMLS_C; #endif
/** * Recursive function to generate a list of class methods for the templates.h * * @param $classN The name of the class to which generate the methods * @param $ctor boolean value to indicate if constructors should be generated or not * @param $output A reference variable where the output of the function will be stored. * @param $multiple_inheritance If true will explictly return all methods it inherit from. * * @return array All function names */ function funcsOfClass($classN, $ctor = 0, &$output, $ar = array(), $multiple_inheritance = false) { global $defIni; $class_methods = ""; if (!isset($defIni[$classN])) { return array(); } $classDef3 = $classDef = $defIni[$classN]; foreach ($classDef as $funcName => $funcDef) { if ($funcName[0] == "_") { continue; } if ($funcDef[0]["virtual"] && $funcDef[0]["protected"] || $funcDef[0]["pure_virtual"] || "" . strpos($funcName, "On") . "" == "0") { continue; } $funcName2 = $funcName; if ($classN == $funcName) { if (!$ctor) { continue; } $funcName2 = "__construct"; } //Rename conflicting method names with PHP keywords $funcName2 = php_method_name($funcName2); if (in_array($funcName2, $ar)) { continue; } $ar[] = $funcName2; $class_methods .= "\tPHP_ME(php_{$classN}, {$funcName2}, NULL, "; if ($funcDef[0]["static"]) { $class_methods .= "ZEND_ACC_STATIC|"; } $class_methods .= "ZEND_ACC_PUBLIC"; if ($funcName2 == "__construct" && $ctor) { $class_methods .= "|ZEND_ACC_CTOR"; } $class_methods .= ")\n"; } //becarefull not to mark a subclasse that is derived from another //this should be recursive if (isset($classDef['_implements']) && count($classDef['_implements']) > 1 || $multiple_inheritance) { $multiple_inheritance = true; foreach ($classDef['_implements'] as $imp) { $ar = array_merge($ar, funcsOfClass($imp, 0, $output, $ar, $multiple_inheritance)); continue; if (!isset($defIni[$imp])) { continue; } $classDef2 = $defIni[$imp]; foreach ($classDef2 as $funcName2 => $funcDef2) { if ($funcName2[0] == "_") { //ignore implements and constructors continue; } $found = false; $funcNamer = $funcName2; if ($funcName2 == $imp) { $funcNamer = $classN; } foreach ($classDef3 as $funcName => $funcDef) { if ($funcNamer == $funcName) { $found = true; } } //if already exists functions with the same name, verify if equal args if ($found) { for ($i = 0; $i < count($funcDef2); $i += 2) { $found = false; for ($e = 0; $e < count($classDef[$funcNamer]); $e += 2) { if ($funcDef2[$i] == $classDef[$funcNamer][$e]) { $found = true; } } if (!$found) { $classDef[$funcNamer][] = $classDef2[$funcName2][$i]; $classDef[$funcNamer][] = $classDef2[$funcName2][$i + 1]; } } } elseif ($funcName2 == $imp) { // prevent foreign constructors //just skip it } else { if ($funcDef[0]["static"]) { $class_methods .= "\tPHP_ME(php_{$imp}, {$funcName2}, NULL, ZEND_ACC_STATIC|ZEND_ACC_PUBLIC)\n"; } else { $class_methods .= "\tPHP_ME(php_{$imp}, {$funcName2}, NULL, ZEND_ACC_PUBLIC)\n"; } } } } } $output .= $class_methods; return $ar; }
?> _free(void *object TSRMLS_DC); zend_object_value php_<?php echo $class_name; ?> _new(zend_class_entry *class_type TSRMLS_DC); END_EXTERN_C() #ifdef WXPHP_INCLUDE_METHOD_TABLES static zend_function_entry php_<?php echo $class_name; ?> _functions[] = { <?php $methods_entry = ""; funcsOfClass($class_name, 1, $methods_entry); print $methods_entry; if (isset($defClassProperties[$class_name]) && isset($defIni[$class_name][$class_name])) { ?> PHP_ME(php_<?php echo $class_name; ?> , __get, wxphp_<?php echo $file_name; ?> _get_args, ZEND_ACC_PUBLIC) <?php } ?> PHP_FE_END };
function funcsOfClass($classN, $ctor = 0, $ar = array()) { global $defIni; global $evnHandlers; if (!isset($defIni[$classN])) { return array(); } $classDef3 = $classDef = $defIni[$classN]; foreach ($classDef as $funcName => $funcDef) { if ($funcName[0] == "_") { continue; } $funcName2 = $funcName; if ($classN == $funcName) { if (!$ctor) { continue; } $funcName2 = "__construct"; } if (in_array($funcName2, $ar)) { continue; } $ar[] = $funcName2; ?> PHP_ME(php_<?php echo $classN; ?> , <?php echo $funcName2; ?> , NULL,ZEND_ACC_PUBLIC<?php if ($funcName2 == "__construct" && $ctor) { ?> |ZEND_ACC_CTOR<?php } ?> ) <?php } //becarefull not to mark a subclasse tha is derived from another //this should be recursive if (isset($classDef['_implements'])) { foreach ($classDef['_implements'] as $imp) { $ar = array_merge($ar, funcsOfClass($imp, 0, $ar)); continue; if (!isset($defIni[$imp])) { continue; } $classDef2 = $defIni[$imp]; foreach ($classDef2 as $funcName2 => $funcDef2) { if ($funcName2[0] == "_") { //ignore implements and constructors continue; } $found = false; $funcNamer = $funcName2; if ($funcName2 == $imp) { $funcNamer = $classN; } foreach ($classDef3 as $funcName => $funcDef) { if ($funcNamer == $funcName) { $found = true; } } //if already exists functions with yhe same name, verify if equal args if ($found) { for ($i = 0; $i < count($funcDef2); $i += 2) { $found = false; for ($e = 0; $e < count($classDef[$funcNamer]); $e += 2) { if ($funcDef2[$i] == $classDef[$funcNamer][$e]) { $found = true; } } if (!$found) { $classDef[$funcNamer][] = $classDef2[$funcName2][$i]; $classDef[$funcNamer][] = $classDef2[$funcName2][$i + 1]; } } } elseif ($funcName2 == $imp) { // prevent foreign constructors //just skip it } else { ?> PHP_ME(php_<?php echo $imp; ?> , <?php echo $funcName2; ?> , NULL,ZEND_ACC_PUBLIC) <?php //$classDef3[$funcName2]=$funcDef2; } } } } if ($classN == "wxFrame") { //var_dump($ar); //var_dump($classDef); //die(); } return $ar; foreach ($classDef as $funcName => $funcDef) { if ($funcName[0] == "_") { continue; } $funcName2 = $funcName; if ($classN == $funcName) { if (!$ctor) { continue; } $funcName2 = "__construct"; } ?> PHP_ME(php_<?php echo $classN; ?> , <?php echo $funcName2; ?> , NULL,ZEND_ACC_PUBLIC<?php if ($funcName2 == "__construct" && $ctor) { ?> |ZEND_ACC_CTOR<?php } ?> ) <?php } if (isset($evnHandlers[$classN]) && $ctor) { ?> PHP_ME(php_<?php echo $classN; ?> , Connect, NULL,ZEND_ACC_PUBLIC) <?php } if (isset($classDef['_implements'])) { /*foreach($classDef['_implements'] as $imp) { if(!isset($defIni[$imp])) continue; $classDef = $defIni[$imp]; foreach($classDef as $funcName => $funcDef) { if($funcName[0]=="_") continue; $funcName2 = $funcName; if($imp==$funcName) continue; ?> PHP_ME(php_<?=$imp?>, <?=$funcName2?>, NULL,ZEND_ACC_PUBLIC) <? } }*/ } else { funcsOfClass($classDef['_extends']); } }