1313use PhpParser \Node \Stmt \Enum_ ;
1414use PhpParser \Node \Stmt \Interface_ ;
1515use PhpParser \Node \Stmt \Trait_ ;
16+ use PhpParser \Node \Stmt \TraitUse ;
1617use PhpParser \PrettyPrinter \Standard ;
1718use PhpParser \PrettyPrinterAbstract ;
1819
@@ -3383,6 +3384,7 @@ class ClassInfo {
33833384 * @param AttributeInfo[] $attributes
33843385 * @param Name[] $extends
33853386 * @param Name[] $implements
3387+ * @param Name[] $uses
33863388 * @param ConstInfo[] $constInfos
33873389 * @param PropertyInfo[] $propertyInfos
33883390 * @param FuncInfo[] $funcInfos
@@ -3401,6 +3403,7 @@ public function __construct(
34013403 private bool $ isNotSerializable ,
34023404 private readonly array $ extends ,
34033405 private readonly array $ implements ,
3406+ private readonly array $ uses ,
34043407 public /* readonly */ array $ constInfos ,
34053408 private /* readonly */ array $ propertyInfos ,
34063409 public array $ funcInfos ,
@@ -3421,6 +3424,9 @@ public function getRegistration(array $allConstInfos): string
34213424 foreach ($ this ->implements as $ implements ) {
34223425 $ params [] = "zend_class_entry *class_entry_ " . implode ("_ " , $ implements ->getParts ());
34233426 }
3427+ foreach ($ this ->uses as $ use ) {
3428+ $ params [] = "zend_class_entry *class_entry_ " . implode ("_ " , $ use ->getParts ());
3429+ }
34243430
34253431 $ escapedName = implode ("_ " , $ this ->name ->getParts ());
34263432
@@ -3518,6 +3524,17 @@ function (Name $item) {
35183524 $ code .= "\tzend_class_implements(class_entry, " . count ($ implements ) . ", " . implode (", " , $ implements ) . "); \n" ;
35193525 }
35203526
3527+ $ traits = array_map (
3528+ function (Name $ item ) {
3529+ return "class_entry_ " . implode ("_ " , $ item ->getParts ());
3530+ },
3531+ $ this ->uses
3532+ );
3533+
3534+ if (!empty ($ traits )) {
3535+ $ code .= "\tzend_class_use_internal_traits(class_entry, " . count ($ traits ) . ", " . implode (", " , $ traits ) . "); \n" ;
3536+ }
3537+
35213538 if ($ this ->alias ) {
35223539 $ code .= "\tzend_register_class_alias( \"" . str_replace ("\\" , "\\\\" , $ this ->alias ) . "\", class_entry); \n" ;
35233540 }
@@ -4408,6 +4425,7 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
44084425 $ propertyInfos = [];
44094426 $ methodInfos = [];
44104427 $ enumCaseInfos = [];
4428+ $ traitUses = [];
44114429 foreach ($ stmt ->stmts as $ classStmt ) {
44124430 $ cond = self ::handlePreprocessorConditions ($ conds , $ classStmt );
44134431 if ($ classStmt instanceof Stmt \Nop) {
@@ -4469,6 +4487,13 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
44694487 $ classStmt ->expr ,
44704488 $ classStmt ->expr ? $ prettyPrinter ->prettyPrintExpr ($ classStmt ->expr ) : null ,
44714489 );
4490+ } else if ($ classStmt instanceof TraitUse) {
4491+ if ($ classStmt ->adaptations ) {
4492+ throw new Exception ("Trait adaptations are not supported " );
4493+ }
4494+ foreach ($ classStmt ->traits as $ trait ) {
4495+ $ traitUses [] = $ trait ;
4496+ }
44724497 } else {
44734498 throw new Exception ("Not implemented {$ classStmt ->getType ()}" );
44744499 }
@@ -4481,6 +4506,7 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
44814506 $ propertyInfos ,
44824507 $ methodInfos ,
44834508 $ enumCaseInfos ,
4509+ $ traitUses ,
44844510 $ cond ,
44854511 $ this ->getMinimumPhpVersionIdCompatibility (),
44864512 $ this ->isUndocumentable
@@ -5167,6 +5193,7 @@ function parseProperty(
51675193 * @param PropertyInfo[] $properties
51685194 * @param FuncInfo[] $methods
51695195 * @param EnumCaseInfo[] $enumCases
5196+ * @param Name[] $traitUses
51705197 */
51715198function parseClass (
51725199 Name $ name ,
@@ -5175,6 +5202,7 @@ function parseClass(
51755202 array $ properties ,
51765203 array $ methods ,
51775204 array $ enumCases ,
5205+ array $ traitUses ,
51785206 ?string $ cond ,
51795207 ?int $ minimumPhpVersionIdCompatibility ,
51805208 bool $ isUndocumentable
@@ -5247,6 +5275,7 @@ function parseClass(
52475275 $ isNotSerializable ,
52485276 $ extends ,
52495277 $ implements ,
5278+ $ traitUses ,
52505279 $ consts ,
52515280 $ properties ,
52525281 $ methods ,
0 commit comments