@@ -1205,6 +1205,40 @@ function printAttrs(path, options, print, { inline = false } = {}) {
12051205 return [ ...allAttrs , inline ? "" : hardline ] ;
12061206}
12071207
1208+ function printPropertyHook ( path , options , print , hook ) {
1209+ const parts = [ ] ;
1210+ if ( hook . byref ) {
1211+ parts . push ( "&" ) ;
1212+ }
1213+ if ( hook . visibility ) {
1214+ parts . push ( hook . visibility , " " ) ;
1215+ }
1216+ if ( hook . isFinal ) {
1217+ parts . push ( "final " ) ;
1218+ }
1219+ parts . push ( hook . name ) ;
1220+
1221+ if ( hook . parameter ) {
1222+ path . call ( ( parameterPath ) => {
1223+ parts . push ( "(" , print ( parameterPath ) , ")" ) ;
1224+ } , "parameter" ) ;
1225+ }
1226+
1227+ if ( hook . body ) {
1228+ if ( hook . body . kind === "block" ) {
1229+ console . log ( hook . body ) ;
1230+ parts . push ( " " , "{" , indent ( [ line , path . call ( print , "body" ) ] ) , line , "}" ) ;
1231+ } else {
1232+ parts . push (
1233+ " => " ,
1234+ path . call ( ( p ) => print ( p ) , "body" ) ,
1235+ ";"
1236+ ) ;
1237+ }
1238+ }
1239+ return group ( parts ) ;
1240+ }
1241+
12081242function printClass ( path , options , print ) {
12091243 const { node } = path ;
12101244 const isAnonymousClass = node . kind === "class" && node . isAnonymous ;
@@ -1782,6 +1816,7 @@ function printNode(path, options, print) {
17821816 case "variadic" :
17831817 return [ "..." , print ( "what" ) ] ;
17841818 case "property" :
1819+ const isInterface = getAncestorNode ( path , "interface" ) ;
17851820 return group ( [
17861821 node . readonly ? "readonly " : "" ,
17871822 node . type ? [ node . nullable ? "?" : "" , print ( "type" ) , " " ] : "" ,
@@ -1799,6 +1834,38 @@ function printNode(path, options, print) {
17991834 ) ,
18001835 ]
18011836 : "" ,
1837+ node . hooks && node . hooks . length > 0 && options . phpVersion >= 8.4
1838+ ? isInterface
1839+ ? [
1840+ " { " ,
1841+ join (
1842+ " " ,
1843+ path . map (
1844+ ( p ) => [
1845+ printPropertyHook ( p , options , print , p . node ) ,
1846+ p . node . body ? "" : ";" ,
1847+ ] ,
1848+ "hooks"
1849+ )
1850+ ) ,
1851+ " }" ,
1852+ ]
1853+ : [
1854+ " {" ,
1855+ indent ( [
1856+ hardline ,
1857+ join (
1858+ [ hardline , hardline ] ,
1859+ path . map (
1860+ ( p ) => printPropertyHook ( p , options , print , p . node ) ,
1861+ "hooks"
1862+ )
1863+ ) ,
1864+ ] ) ,
1865+ hardline ,
1866+ "}" ,
1867+ ]
1868+ : "" ,
18021869 ] ) ;
18031870 case "propertystatement" : {
18041871 const attrs = [ ] ;
0 commit comments