@@ -815,33 +815,35 @@ class ArgInfo {
815
815
public $ phpDocType ;
816
816
/** @var string|null */
817
817
public $ defaultValue ;
818
- /** @var bool */
819
- public $ isSensitive ;
818
+ /** @var AttributeInfo[] */
819
+ public $ attributes ;
820
820
821
+ /**
822
+ * @param AttributeInfo[] $attributes
823
+ */
821
824
public function __construct (
822
825
string $ name ,
823
826
int $ sendBy ,
824
827
bool $ isVariadic ,
825
828
?Type $ type ,
826
829
?Type $ phpDocType ,
827
830
?string $ defaultValue ,
828
- bool $ isSensitive
831
+ array $ attributes
829
832
) {
830
833
$ this ->name = $ name ;
831
834
$ this ->sendBy = $ sendBy ;
832
835
$ this ->isVariadic = $ isVariadic ;
833
836
$ this ->setTypes ($ type , $ phpDocType );
834
837
$ this ->defaultValue = $ defaultValue ;
835
- $ this ->isSensitive = $ isSensitive ;
838
+ $ this ->attributes = $ attributes ;
836
839
}
837
840
838
841
public function equals (ArgInfo $ other ): bool {
839
842
return $ this ->name === $ other ->name
840
843
&& $ this ->sendBy === $ other ->sendBy
841
844
&& $ this ->isVariadic === $ other ->isVariadic
842
845
&& Type::equals ($ this ->type , $ other ->type )
843
- && $ this ->defaultValue === $ other ->defaultValue
844
- && $ this ->isSensitive === $ other ->isSensitive ;
846
+ && $ this ->defaultValue === $ other ->defaultValue ;
845
847
}
846
848
847
849
public function getSendByString (): string {
@@ -2570,7 +2572,7 @@ function (Name $item) {
2570
2572
}
2571
2573
}
2572
2574
2573
- if ($ attributeInitializationCode = generateAttributeInitialization ($ this ->funcInfos , $ this ->cond )) {
2575
+ if ($ attributeInitializationCode = generateAttributeInitialization ($ this ->funcInfos , $ this ->cond , $ allConstInfos )) {
2574
2576
if (!$ php82MinimumCompatibility ) {
2575
2577
$ code .= "#if (PHP_VERSION_ID >= " . PHP_82_VERSION_ID . ") \n" ;
2576
2578
}
@@ -3259,16 +3261,10 @@ function parseFunctionLike(
3259
3261
foreach ($ func ->getParams () as $ i => $ param ) {
3260
3262
$ varName = $ param ->var ->name ;
3261
3263
$ preferRef = !empty ($ paramMeta [$ varName ]['prefer-ref ' ]);
3262
- $ isSensitive = false ;
3264
+ $ attributes = [] ;
3263
3265
foreach ($ param ->attrGroups as $ attrGroup ) {
3264
3266
foreach ($ attrGroup ->attrs as $ attr ) {
3265
- switch ($ attr ->name ->toCodeString ()) {
3266
- case '\\SensitiveParameter ' :
3267
- $ isSensitive = true ;
3268
- break ;
3269
- default :
3270
- throw new Exception ("Unhandled attribute {$ attr ->name ->toCodeString ()}. " );
3271
- }
3267
+ $ attributes [] = new AttributeInfo ($ attr ->name ->toString (), $ attr ->args );
3272
3268
}
3273
3269
}
3274
3270
unset($ paramMeta [$ varName ]);
@@ -3318,7 +3314,7 @@ function parseFunctionLike(
3318
3314
$ type ,
3319
3315
isset ($ docParamTypes [$ varName ]) ? Type::fromString ($ docParamTypes [$ varName ]) : null ,
3320
3316
$ param ->default ? $ prettyPrinter ->prettyPrintExpr ($ param ->default ) : null ,
3321
- $ isSensitive
3317
+ $ attributes
3322
3318
);
3323
3319
if (!$ param ->default && !$ param ->variadic ) {
3324
3320
$ numRequiredArgs = $ i + 1 ;
@@ -3972,7 +3968,7 @@ static function (FuncInfo $funcInfo) use ($fileInfo, &$generatedFunctionDeclarat
3972
3968
}
3973
3969
3974
3970
if ($ fileInfo ->generateClassEntries ) {
3975
- $ attributeInitializationCode = generateAttributeInitialization ($ fileInfo ->funcInfos );
3971
+ $ attributeInitializationCode = generateAttributeInitialization ($ fileInfo ->funcInfos , null , $ allConstInfos );
3976
3972
3977
3973
if ($ attributeInitializationCode !== "" || !empty ($ fileInfo ->constInfos )) {
3978
3974
$ code .= "\nstatic void register_ {$ stubFilenameWithoutExtension }_symbols(int module_number) \n" ;
@@ -4039,25 +4035,23 @@ function generateFunctionEntries(?Name $className, array $funcInfos, ?string $co
4039
4035
/**
4040
4036
* @param iterable<FuncInfo> $funcInfos
4041
4037
*/
4042
- function generateAttributeInitialization (iterable $ funcInfos , ?string $ parentCond = null ): string {
4038
+ function generateAttributeInitialization (iterable $ funcInfos , ?string $ parentCond = null , iterable $ allConstInfos ): string {
4043
4039
return generateCodeWithConditions (
4044
4040
$ funcInfos ,
4045
4041
"" ,
4046
- static function (FuncInfo $ funcInfo ) {
4042
+ static function (FuncInfo $ funcInfo ) use ( $ allConstInfos ) {
4047
4043
$ code = null ;
4048
4044
4049
4045
foreach ($ funcInfo ->args as $ index => $ arg ) {
4050
- if (!$ arg ->isSensitive ) {
4051
- continue ;
4052
- }
4053
-
4054
4046
if ($ funcInfo ->name instanceof MethodName) {
4055
4047
$ functionTable = "&class_entry->function_table " ;
4056
4048
} else {
4057
4049
$ functionTable = "CG(function_table) " ;
4058
4050
}
4059
4051
4060
- $ code .= "\tzend_mark_function_parameter_as_sensitive( $ functionTable, \"" . $ funcInfo ->name ->getNameForAttributes () . "\", $ index); \n" ;
4052
+ foreach ($ arg ->attributes as $ attribute ) {
4053
+ $ code .= $ attribute ->generateCode ("zend_add_parameter_attribute(zend_hash_str_find_ptr( $ functionTable, \"" . $ funcInfo ->name ->getNameForAttributes () . "\", sizeof( \"" . $ funcInfo ->name ->getNameForAttributes () . "\") - 1), $ index " , "{$ funcInfo ->getArgInfoName ()}_arg {$ index }" , $ allConstInfos );
4054
+ }
4061
4055
}
4062
4056
4063
4057
return $ code ;
0 commit comments