@@ -2058,7 +2058,6 @@ public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLeve
2058
2058
$ constantElement ->textContent = $ this ->name ->__toString ();
2059
2059
2060
2060
$ typeElement = ($ this ->phpDocType ?? $ this ->type )->getTypeForDoc ($ doc );
2061
- $ stubConstantType = $ constantElement ->textContent ;
2062
2061
2063
2062
$ termElement ->appendChild (new DOMText ("\n$ indentation " ));
2064
2063
$ termElement ->appendChild ($ constantElement );
@@ -2069,6 +2068,24 @@ public function getPredefinedConstantTerm(DOMDocument $doc, int $indentationLeve
2069
2068
return $ termElement ;
2070
2069
}
2071
2070
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
+
2072
2089
public function discardInfoForOldPhpVersions (): void {
2073
2090
$ this ->type = null ;
2074
2091
$ this ->flags &= ~Class_::MODIFIER_FINAL ;
@@ -4510,7 +4527,7 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
4510
4527
4511
4528
foreach ($ it as $ file ) {
4512
4529
$ pathName = $ file ->getPathName ();
4513
- if (!preg_match ('/constants\. xml$/i ' , $ pathName )) {
4530
+ if (!preg_match ('/(?:[\w\.]* constants[\w\.]*|tokens|filters). xml$/i ' , basename ( $ pathName) )) {
4514
4531
continue ;
4515
4532
}
4516
4533
@@ -4519,7 +4536,7 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
4519
4536
continue ;
4520
4537
}
4521
4538
4522
- if (stripos ($ xml , "<appendix " ) === false ) {
4539
+ if (stripos ($ xml , "<appendix " ) === false && stripos ( $ xml , " <sect2 " ) === false && stripos ( $ xml , " <chapter " ) === false ) {
4523
4540
continue ;
4524
4541
}
4525
4542
@@ -4542,39 +4559,74 @@ function replacePredefinedConstants(string $targetDirectory, array $constMap, ar
4542
4559
continue ;
4543
4560
}
4544
4561
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 );
4549
4589
}
4590
+ }
4550
4591
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) {
4554
4594
continue ;
4555
4595
}
4556
- $ manualConstantName = $ manualConstantElement ->textContent ;
4557
4596
4558
- $ stubConstant = $ constMap [ $ manualConstantName ] ?? null ;
4559
- if ($ stubConstant === null ) {
4597
+ $ entry = $ row -> getElementsByTagName ( " entry " )-> item ( 0 ) ;
4598
+ if (! $ entry instanceof DOMElement ) {
4560
4599
continue ;
4561
4600
}
4562
4601
4563
- $ documentedConstMap [$ manualConstantName ] = $ manualConstantName ;
4602
+ foreach ($ entry ->getElementsByTagName ("constant " ) as $ manualConstantElement ) {
4603
+ if (!$ manualConstantElement instanceof DOMElement) {
4604
+ continue ;
4605
+ }
4564
4606
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 ;
4571
4608
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 );
4575
4622
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
+ }
4578
4630
}
4579
4631
4580
4632
if ($ updated ) {
@@ -4871,8 +4923,7 @@ function replaceMethodSynopses(
4871
4923
continue ;
4872
4924
}
4873
4925
4874
- $ list = $ methodSynopsis ->getElementsByTagName ("methodname " );
4875
- $ item = $ list ->item (0 );
4926
+ $ item = $ methodSynopsis ->getElementsByTagName ("methodname " )->item (0 );
4876
4927
if (!$ item instanceof DOMElement) {
4877
4928
continue ;
4878
4929
}
0 commit comments