@@ -2058,7 +2058,6 @@ public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLeve
20582058 $ constantElement ->textContent = $ this ->name ->__toString ();
20592059
20602060 $ typeElement = ($ this ->phpDocType ?? $ this ->type )->getTypeForDoc ($ doc );
2061- $ stubConstantType = $ constantElement ->textContent ;
20622061
20632062 $ termElement ->appendChild (new DOMText ("\n$ indentation " ));
20642063 $ termElement ->appendChild ($ constantElement );
@@ -2069,6 +2068,24 @@ public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLeve
20692068 return $ termElement ;
20702069 }
20712070
2071+ public function getPredefinedConstantEntry (DOMDocument $ doc , int $ indentationLevel ): DOMElement {
2072+ $ indentation = str_repeat (" " , $ indentationLevel );
2073+
2074+ $ entryElement = $ doc ->createElement ("entry " );
2075+
2076+ $ constantElement = $ doc ->createElement ("constant " );
2077+ $ constantElement ->textContent = $ this ->name ->__toString ();
2078+ $ typeElement = ($ this ->phpDocType ?? $ this ->type )->getTypeForDoc ($ doc );
2079+
2080+ $ entryElement ->appendChild (new DOMText ("\n$ indentation " ));
2081+ $ entryElement ->appendChild ($ constantElement );
2082+ $ entryElement ->appendChild (new DOMText ("\n$ indentation ( " ));
2083+ $ entryElement ->appendChild ($ typeElement );
2084+ $ entryElement ->appendChild (new DOMText (") \n$ indentation " ));
2085+
2086+ return $ entryElement ;
2087+ }
2088+
20722089 public function discardInfoForOldPhpVersions (): void {
20732090 $ this ->type = null ;
20742091 $ this ->flags &= ~Class_::MODIFIER_FINAL ;
@@ -4510,7 +4527,7 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
45104527
45114528 foreach ($ it as $ file ) {
45124529 $ pathName = $ file ->getPathName ();
4513- if (!preg_match ('/constants\. xml$/i ' , $ pathName )) {
4530+ if (!preg_match ('/(?:[\w\.]* constants[\w\.]*|tokens|filters). xml$/i ' , basename ( $ pathName) )) {
45144531 continue ;
45154532 }
45164533
@@ -4519,7 +4536,7 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
45194536 continue ;
45204537 }
45214538
4522- if (stripos ($ xml , "<appendix " ) === false ) {
4539+ if (stripos ($ xml , "<appendix " ) === false && stripos ( $ xml , " <sect2 " ) === false && stripos ( $ xml , " <chapter " ) === false ) {
45234540 continue ;
45244541 }
45254542
@@ -4542,39 +4559,74 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
45424559 continue ;
45434560 }
45444561
4545- $ list = $ entry ->getElementsByTagName ("term " );
4546- $ manualTermElement = $ list ->item (0 );
4547- if (!$ manualTermElement instanceof DOMElement) {
4548- continue ;
4562+ foreach ($ entry ->getElementsByTagName ("term " ) as $ manualTermElement ) {
4563+ $ manualConstantElement = $ manualTermElement ->getElementsByTagName ("constant " )->item (0 );
4564+ if (!$ manualConstantElement instanceof DOMElement) {
4565+ continue ;
4566+ }
4567+
4568+ $ manualConstantName = $ manualConstantElement ->textContent ;
4569+
4570+ $ stubConstant = $ constMap [$ manualConstantName ] ?? null ;
4571+ if ($ stubConstant === null ) {
4572+ continue ;
4573+ }
4574+
4575+ $ documentedConstMap [$ manualConstantName ] = $ manualConstantName ;
4576+
4577+ if ($ entry ->firstChild instanceof DOMText) {
4578+ $ indentationLevel = strlen (str_replace ("\n" , "" , $ entry ->firstChild ->textContent ));
4579+ } else {
4580+ $ indentationLevel = 3 ;
4581+ }
4582+ $ newTermElement = $ stubConstant ->getPredefinedConstantTerm ($ doc , $ indentationLevel );
4583+
4584+ if ($ manualTermElement ->textContent === $ newTermElement ->textContent ) {
4585+ continue ;
4586+ }
4587+
4588+ $ manualTermElement ->parentNode ->replaceChild ($ newTermElement , $ manualTermElement );
45494589 }
4590+ }
45504591
4551- $ list = $ manualTermElement ->getElementsByTagName ("constant " );
4552- $ manualConstantElement = $ list ->item (0 );
4553- if (!$ manualConstantElement instanceof DOMElement) {
4592+ foreach ($ doc ->getElementsByTagName ("row " ) as $ row ) {
4593+ if (!$ row instanceof DOMElement) {
45544594 continue ;
45554595 }
4556- $ manualConstantName = $ manualConstantElement ->textContent ;
45574596
4558- $ stubConstant = $ constMap [ $ manualConstantName ] ?? null ;
4559- if ($ stubConstant === null ) {
4597+ $ entry = $ row -> getElementsByTagName ( " entry " )-> item ( 0 ) ;
4598+ if (! $ entry instanceof DOMElement ) {
45604599 continue ;
45614600 }
45624601
4563- $ documentedConstMap [$ manualConstantName ] = $ manualConstantName ;
4602+ foreach ($ entry ->getElementsByTagName ("constant " ) as $ manualConstantElement ) {
4603+ if (!$ manualConstantElement instanceof DOMElement) {
4604+ continue ;
4605+ }
45644606
4565- if ($ entry ->firstChild instanceof DOMText) {
4566- $ indentationLevel = strlen (str_replace ("\n" , "" , $ entry ->firstChild ->textContent ));
4567- } else {
4568- $ indentationLevel = 3 ;
4569- }
4570- $ newTermElement = $ stubConstant ->getPredefinedConstantTerm ($ doc , $ indentationLevel );
4607+ $ manualConstantName = $ manualConstantElement ->textContent ;
45714608
4572- if ($ manualTermElement ->textContent === $ newTermElement ->textContent ) {
4573- continue ;
4574- }
4609+ $ stubConstant = $ constMap [$ manualConstantName ] ?? null ;
4610+ if ($ stubConstant === null ) {
4611+ continue ;
4612+ }
4613+
4614+ $ documentedConstMap [$ manualConstantName ] = $ manualConstantName ;
4615+
4616+ if ($ row ->firstChild instanceof DOMText) {
4617+ $ indentationLevel = strlen (str_replace ("\n" , "" , $ row ->firstChild ->textContent ));
4618+ } else {
4619+ $ indentationLevel = 3 ;
4620+ }
4621+ $ newEntryElement = $ stubConstant ->getPredefinedConstantEntry ($ doc , $ indentationLevel );
45754622
4576- $ manualTermElement ->parentNode ->replaceChild ($ newTermElement , $ manualTermElement );
4577- $ updated = true ;
4623+ if ($ entry ->textContent === $ newEntryElement ->textContent ) {
4624+ continue ;
4625+ }
4626+
4627+ $ entry ->parentNode ->replaceChild ($ newEntryElement , $ entry );
4628+ $ updated = true ;
4629+ }
45784630 }
45794631
45804632 if ($ updated ) {
@@ -4871,8 +4923,7 @@ function replaceMethodSynopses(
48714923 continue ;
48724924 }
48734925
4874- $ list = $ methodSynopsis ->getElementsByTagName ("methodname " );
4875- $ item = $ list ->item (0 );
4926+ $ item = $ methodSynopsis ->getElementsByTagName ("methodname " )->item (0 );
48764927 if (!$ item instanceof DOMElement) {
48774928 continue ;
48784929 }
0 commit comments