@@ -20,19 +20,12 @@ class EndpointCrawler
2020 private const BASE_URL = 'https://start.exactonline.nl/docs/ ' ;
2121 private const ATTRIBUTE_HEADER_XPATH = '//table[@id="referencetable"]/tr[1] ' ;
2222 private const ATTRIBUTE_ROWS_XPATH = '//table[@id="referencetable"]/tr[position()>1] ' ;
23+ private PageRegistry $ pagesToVisit ;
24+ private PageRegistry $ visitedPages ;
25+ private ?Crawler $ domCrawler = null ;
2326
24- /** @var EndpointCrawlerConfig */
25- private $ config ;
26- /** @var PageRegistry */
27- private $ pagesToVisit ;
28- /** @var PageRegistry */
29- private $ visitedPages ;
30- /** @var Crawler */
31- private $ domCrawler ;
32-
33- public function __construct (EndpointCrawlerConfig $ config , ?PageRegistry $ pagesToVisit = null )
27+ public function __construct (private EndpointCrawlerConfig $ config , ?PageRegistry $ pagesToVisit = null )
3428 {
35- $ this ->config = $ config ;
3629 $ this ->pagesToVisit = $ pagesToVisit ?? $ this ->createDefaultPagesToVisit ();
3730 $ this ->visitedPages = new PageRegistry ();
3831 }
@@ -83,7 +76,7 @@ private function crawlWebPage(string $url): ?Endpoint
8376 $ scope = $ this ->domCrawler ->filterXPath ('//*[@id="scope"] ' )->first ()->text ();
8477 try {
8578 $ uri = $ this ->domCrawler ->filterXPath ('//*[@id="serviceUri"] ' )->first ()->text ();
86- } catch (\Exception $ exception ) {
79+ } catch (\Exception ) {
8780 return null ;
8881 }
8982 $ supportedMethodsCrawler = $ this ->domCrawler ->filterXPath ('//input[@name="supportedmethods"] ' );
@@ -107,9 +100,7 @@ private function crawlWebPage(string $url): ?Endpoint
107100 return null ;
108101 }
109102
110- $ columns = array_map (static function ($ n ) {
111- return explode (' ' , $ n ->nodeValue )[0 ];
112- }, $ header ->children ()->getIterator ()->getArrayCopy ());
103+ $ columns = array_map (static fn ($ n ) => explode (' ' , $ n ->nodeValue )[0 ], $ header ->children ()->getIterator ()->getArrayCopy ());
113104
114105 $ propertyRowParserConfig = new PropertyRowParserConfig (
115106 array_search ('Type ' , $ columns , true ) + 1 ,
@@ -122,7 +113,7 @@ private function crawlWebPage(string $url): ?Endpoint
122113
123114 $ goodToKnows = $ this ->domCrawler ->filterXPath ('//*[@id="goodToKnow"] ' );
124115 $ deprecationMessage = 'This endpoint is redundant and is going to be removed. ' ;
125- $ isDeprecated = $ goodToKnows ->count () > 0 && strpos ($ goodToKnows ->first ()->text (), $ deprecationMessage ) !== false ;
116+ $ isDeprecated = $ goodToKnows ->count () > 0 && str_contains ($ goodToKnows ->first ()->text (), $ deprecationMessage );
126117 return new Endpoint (
127118 $ endpoint ,
128119 $ url ,
@@ -137,7 +128,16 @@ private function crawlWebPage(string $url): ?Endpoint
137128
138129 private function fetchHtmlFromUrl (string $ url ): string
139130 {
140- $ html = file_get_contents ($ url );
131+ [,$ basename ] = explode ('= ' , $ url );
132+ $ filename = sys_get_temp_dir () . '/exact-online-meta-data-tool- ' . strtolower ($ basename ) . '.html ' ;
133+
134+ if (!file_exists ($ filename )) {
135+ $ html = file_get_contents ($ url );
136+ file_put_contents ($ filename , $ html );
137+ } else {
138+ $ html = file_get_contents ($ filename );
139+ }
140+
141141 $ this ->visitedPages ->add ($ url );
142142
143143 if ($ html === false ) {
@@ -166,16 +166,16 @@ private function getPropertyRowParser(PropertyRowParserConfig $config): \Closure
166166 if ($ name === 'ID ' ) {
167167 $ httpMethods = $ httpMethods ->addDelete ();
168168 }
169- if (strpos ($ class , 'hideput ' ) === false && strpos ($ class , 'showget ' ) === false ) {
169+ if (! str_contains ($ class , 'hideput ' ) && ! str_contains ($ class , 'showget ' )) {
170170 $ httpMethods = $ httpMethods ->addPut ();
171171 }
172- if (strpos ($ class , 'hidepost ' ) === false && strpos ($ class , 'showget ' ) === false ) {
172+ if (! str_contains ($ class , 'hidepost ' ) && ! str_contains ($ class , 'showget ' )) {
173173 $ httpMethods = $ httpMethods ->addPost ();
174174 }
175175 if ($ name === 'ID ' ) {
176176 $ httpMethods = HttpMethodMask::all ();
177177 }
178- $ hidden = strpos ($ node ->attr ('class ' ) ?? '' , 'hiderow ' ) !== false ;
178+ $ hidden = str_contains ($ node ->attr ('class ' ) ?? '' , 'hiderow ' );
179179 $ mandatory = strtolower (trim ($ node ->filterXpath ("//td[ {$ config ->getMandatoryColumnIndex ()}] " )->text ())) === 'true ' ;
180180
181181 return new Property ($ name , $ type , $ description , $ primaryKey , $ httpMethods , $ hidden , $ mandatory );
0 commit comments