@@ -7,7 +7,7 @@ class NewsFetcher {
77 private const RAW_CONTENT_URL = 'https://raw.githubusercontent.com/php/php-src/%tag/NEWS ' ;
88
99 private const REGEX_PIPE_HEADER = '/^\|+$/ ' ;
10- private const REGEX_RELEASE_HEADER = '/^(?<date>(?<day>\d\d|\?\?) (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|\?\?\?) (?<year>\?\?\?\?|20\d\d)), PHP (?<release_id>\d\.\d\.\d\d?)$/ ' ;
10+ private const REGEX_RELEASE_HEADER = '/^(?<date>(?<day>\d\d|\?\?) (?<month>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|\?\?\?) (?<year>\?\?\?\?|20\d\d)), PHP (?<release_id>\d\.\d\.(?: \d\d?|0(?:alpha\d|beta\d|rc\d|RC\d)?) )$/ ' ;
1111 private const REGEX_EXT_HEADER = '/^- (?<ext_name>[A-Za-z][A-Za-z _\/\d]+):?$/ ' ;
1212
1313 private const REGEX_CHANGE_RECORD_START = '/^ \. (?<change_record>.*)$/ ' ;
@@ -21,16 +21,27 @@ public function __construct(string $apiKey = null) {
2121 $ this ->curlFetcher = new CurlFetcher ();
2222 }
2323
24- public function fetchAllForVersion (int $ version ): array {
25- preg_match ('/^(?<major>^\d)0(?<minor>\d)\d\d?$/ ' , (string ) $ version , $ matches );
24+ public function fetchAllForVersion (int |string $ version ): array {
2625
27- if (empty ($ matches )) {
28- throw new \InvalidArgumentException ('Invalid $version: Must be in integer "XYYZZ" format ' );
26+ if (is_string ($ version )) {
27+ if ($ version !== 'master ' ) {
28+ throw new \InvalidArgumentException ('String arguments must be "master" ' );
29+ }
30+ $ baseUrl = strtr (static ::RAW_CONTENT_URL , [
31+ '%tag ' => 'master ' ,
32+ ]);
2933 }
34+ else {
35+ preg_match ('/^(?<major>^\d)0(?<minor>\d)\d\d?$/ ' , (string ) $ version , $ matches );
36+
37+ if (empty ($ matches )) {
38+ throw new \InvalidArgumentException ('Invalid $version: Must be in integer "XYYZZ" format ' );
39+ }
3040
31- $ baseUrl = strtr (static ::RAW_CONTENT_URL , [
32- '%tag ' => "PHP- {$ matches ['major ' ]}. {$ matches ['minor ' ]}" ,
33- ]);
41+ $ baseUrl = strtr (static ::RAW_CONTENT_URL , [
42+ '%tag ' => "PHP- {$ matches ['major ' ]}. {$ matches ['minor ' ]}" ,
43+ ]);
44+ }
3445
3546 $ headers = [];
3647 if ($ this ->apiKey ) {
@@ -72,7 +83,6 @@ private function parseNewsPage(string $contents): array {
7283 $ cursorExt = null ;
7384 $ lastLine = null ;
7485
75-
7686 continue ;
7787 }
7888
@@ -127,6 +137,10 @@ private function skipLine(mixed $line, int $lineNo): bool {
127137 return true ;
128138 }
129139
140+ if (str_starts_with ($ line , '<<< NOTE: Insert NEWS ' )) {
141+ return true ;
142+ }
143+
130144 return false ;
131145 }
132146
0 commit comments