cvs: ZendEngine2 / zend_reflection_api.c

From: Date: Sun, 25 Jul 2004 07:06:53 +0000
Subject: cvs: ZendEngine2 / zend_reflection_api.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-2798@lists.php.net to get a copy of this message
helly Sun Jul 25 03:06:53 2004 EDT Modified files: /ZendEngine2 zend_reflection_api.c Log: - Add ReflectionParameter::isOptional() to test whether a parameter is optional and also show this information in export. http://cvs.php.net/diff.php/ZendEngine2/zend_reflection_api.c?r1=1.115&r2=1.116&ty=u Index: ZendEngine2/zend_reflection_api.c diff -u ZendEngine2/zend_reflection_api.c:1.115 ZendEngine2/zend_reflection_api.c:1.116 --- ZendEngine2/zend_reflection_api.c:1.115 Tue Jul 20 14:22:31 2004 +++ ZendEngine2/zend_reflection_api.c Sun Jul 25 03:06:53 2004 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_reflection_api.c,v 1.115 2004/07/20 18:22:31 helly Exp $ */ +/* $Id: zend_reflection_api.c,v 1.116 2004/07/25 07:06:53 helly Exp $ */ #include "zend.h" #include "zend_API.h" #include "zend_exceptions.h" @@ -146,6 +146,7 @@ /* Struct for parameters */ typedef struct _parameter_reference { int offset; + int required; struct _zend_arg_info *arg_info; } parameter_reference; @@ -501,9 +502,14 @@ /* }}} */ /* {{{ _parameter_string */ -static void _parameter_string(string *str, struct _zend_arg_info *arg_info, int offset, char* indent TSRMLS_DC) +static void _parameter_string(string *str, struct _zend_arg_info *arg_info, int offset, int required, char* indent TSRMLS_DC) { string_printf(str, "Parameter #%d [ ", offset); + if (offset >= required) { + string_printf(str, "<optional> "); + } else { + string_printf(str, "<required> "); + } if (arg_info->class_name) { string_printf(str, "%s ", arg_info->class_name); if (arg_info->allow_null) { @@ -527,6 +533,7 @@ { zend_uint i; struct _zend_arg_info *arg_info = fptr->common.arg_info; + int required = fptr->common.required_num_args; if (!arg_info) { return; @@ -536,7 +543,7 @@ string_printf(str, "%s- Parameters [%d] {\n", indent, fptr->common.num_args); for (i = 0; i < fptr->common.num_args; i++) { string_printf(str, "%s ", indent); - _parameter_string(str, arg_info, i, indent TSRMLS_CC); + _parameter_string(str, arg_info, i, required, indent TSRMLS_CC); string_write(str, "\n", sizeof("\n")-1); arg_info++; } @@ -1511,6 +1518,7 @@ ref = (parameter_reference*) emalloc(sizeof(parameter_reference)); ref->arg_info = &arg_info[position]; ref->offset = position; + ref->required = fptr->common.required_num_args; intern->ptr = ref; intern->free_ptr = 1; } @@ -1527,7 +1535,7 @@ METHOD_NOTSTATIC_NUMPARAMS(0); GET_REFLECTION_OBJECT_PTR(param); string_init(&str); - _parameter_string(&str, param->arg_info, param->offset, "" TSRMLS_CC); + _parameter_string(&str, param->arg_info, param->offset, param->required, "" TSRMLS_CC); RETURN_STRINGL(str.string, str.len - 1, 0); } /* }}} */ @@ -1597,6 +1605,20 @@ } /* }}} */ +/* {{{ proto public bool ReflectionParameter::isOptional() + Returns whether this parameter is an optional parameter */ +ZEND_METHOD(reflection_parameter, isOptional) +{ + reflection_object *intern; + parameter_reference *param; + + METHOD_NOTSTATIC_NUMPARAMS(0); + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->offset >= param->required); +} +/* }}} */ + /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name, [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_method, export) @@ -3331,6 +3353,7 @@ ZEND_ME(reflection_parameter, isPassedByReference, NULL, 0) ZEND_ME(reflection_parameter, getClass, NULL, 0) ZEND_ME(reflection_parameter, allowsNull, NULL, 0) + ZEND_ME(reflection_parameter, isOptional, NULL, 0) {NULL, NULL, NULL} };

« previous php.zend-engine.cvs (#2798) next »