File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed
Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -77,8 +77,14 @@ public function __construct(Request $request, array $config = null)
7777 $ this ->run ();
7878
7979 if ($ request ->url ->getUrl () !== $ this ->url ) {
80- $ this ->request = $ request ->createRequest ($ this ->url );
81- $ this ->run ();
80+ $ subRequest = $ request ->createRequest ($ this ->url );
81+
82+ if ($ subRequest ->isValid ()) {
83+ $ this ->request = $ subRequest ;
84+ $ this ->run ();
85+ } else {
86+ $ this ->url = $ request ->url ->getUrl ();
87+ }
8288 }
8389 }
8490
Original file line number Diff line number Diff line change @@ -24,11 +24,11 @@ public function run()
2424 $ endPoint = null ;
2525 $ params = $ this ->config ['parameters ' ];
2626
27- if (($ html = $ this ->request ->getHtmlContent ()) && ($ endPoint = self ::getEndPointFromDom ($ html ))) {
28- $ params [ ' url ' ] = $ this ->request -> url -> getUrl ();
29- } elseif (( $ info = self :: getEndPointFromRequest ( $ this -> request , $ this -> config ))) {
30- $ endPoint = $ info ['endPoint ' ];
31- $ params += $ info [ ' params ' ];
27+ if (! ($ html = $ this ->request ->getHtmlContent ()) || ! ($ endPoint = self ::getEndPointFromDom ($ html ))) {
28+ if (( $ info = self :: getEndPointFromRequest ( $ this ->request , $ this -> config ))) {
29+ $ endPoint = $ info [ ' endPoint ' ];
30+ $ params + = $ info ['params ' ];
31+ }
3232 }
3333
3434 if (!$ endPoint ) {
@@ -38,6 +38,10 @@ public function run()
3838 $ endPointRequest = $ this ->request ->createRequest ($ endPoint );
3939 $ endPointRequest ->startingUrl ->setParameter ($ params );
4040
41+ if (!$ endPointRequest ->startingUrl ->hasParameter ('url ' )) {
42+ $ endPointRequest ->startingUrl ->setParameter ('url ' , $ this ->request ->url ->getUrl ());
43+ }
44+
4145 // extract from xml
4246 if (($ endPointRequest ->url ->getExtension () === 'xml ' ) || ($ endPointRequest ->url ->getParameter ('format ' ) === 'xml ' )) {
4347 if ($ parameters = $ endPointRequest ->getXmlContent ()) {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ class Request
1111{
1212 public $ startingUrl ;
1313
14+ private static $ cache = [];
1415 private $ resolverClass = 'Embed \\RequestResolvers \\Curl ' ;
1516 private $ resolverConfig ;
1617
@@ -48,7 +49,13 @@ public function __get($name)
4849 return $ this ->url = new Url ($ this ->resolver ->getUrl ());
4950
5051 case 'resolver ' :
51- $ this ->resolver = new $ this ->resolverClass (UrlRedirect::resolve ($ this ->startingUrl ->getUrl ()));
52+ $ url = UrlRedirect::resolve ($ this ->startingUrl ->getUrl ());
53+
54+ if (isset (self ::$ cache [$ url ])) {
55+ $ this ->resolver = self ::$ cache [$ url ];
56+ } else {
57+ $ this ->resolver = self ::$ cache [$ url ] = new $ this ->resolverClass ($ url );
58+ }
5259
5360 if (is_array ($ this ->resolverConfig )) {
5461 $ this ->resolver ->setConfig ($ this ->resolverConfig );
You can’t perform that action at this time.
0 commit comments