@@ -67,12 +67,6 @@ class Request
6767 */
6868 protected string $ method ;
6969
70- /**
71- * All options that have been passed to
72- * the request in the constructor
73- */
74- protected array $ options ;
75-
7670 /**
7771 * The Query object is a wrapper around
7872 * the URL query string, which parses the
@@ -96,9 +90,9 @@ class Request
9690 * data via the $options array or use
9791 * the data from the incoming request.
9892 */
99- public function __construct (array $ options = [])
100- {
101- $ this -> options = $ options ;
93+ public function __construct (
94+ protected array $ options = []
95+ ) {
10296 $ this ->method = $ this ->detectRequestMethod ($ options ['method ' ] ?? null );
10397
10498 if (isset ($ options ['body ' ]) === true ) {
@@ -155,7 +149,7 @@ public function auth(): Auth|false|null
155149 }
156150
157151 // lazily request the instance for non-CMS use cases
158- $ kirby = App::instance (null , true );
152+ $ kirby = App::instance (lazy: true );
159153
160154 // tell the CMS responder that the response relies on
161155 // the `Authorization` header and its value (even if
@@ -224,13 +218,26 @@ public function data(): array
224218 public function detectRequestMethod (string |null $ method = null ): string
225219 {
226220 // all possible methods
227- $ methods = ['GET ' , 'HEAD ' , 'POST ' , 'PUT ' , 'DELETE ' , 'CONNECT ' , 'OPTIONS ' , 'TRACE ' , 'PATCH ' ];
221+ $ methods = [
222+ 'CONNECT ' ,
223+ 'DELETE ' ,
224+ 'GET ' ,
225+ 'HEAD ' ,
226+ 'OPTIONS ' ,
227+ 'PATCH ' ,
228+ 'POST ' ,
229+ 'PUT ' ,
230+ 'TRACE ' ,
231+ ];
228232
229233 // the request method can be overwritten with a header
230- $ methodOverride = strtoupper (Environment::getGlobally ('HTTP_X_HTTP_METHOD_OVERRIDE ' , '' ));
234+ if ($ method === null ) {
235+ $ override = Environment::getGlobally ('HTTP_X_HTTP_METHOD_OVERRIDE ' , '' );
236+ $ override = strtoupper ($ override );
231237
232- if (in_array ($ methodOverride , $ methods , true ) === true ) {
233- $ method ??= $ methodOverride ;
238+ if (in_array ($ override , $ methods , true ) === true ) {
239+ $ method = $ override ;
240+ }
234241 }
235242
236243 // final chain of options to detect the method
@@ -410,14 +417,15 @@ protected function authString(): string|null
410417 // both variants need to be checked separately
411418 // because empty strings are treated as invalid
412419 // but the `??` operator wouldn't do the fallback
413-
414420 $ option = $ this ->options ['auth ' ] ?? null ;
415- if (empty ($ option ) === false ) {
421+
422+ if (is_string ($ option ) === true && $ option !== '' ) {
416423 return $ option ;
417424 }
418425
419426 $ header = $ this ->header ('authorization ' );
420- if (empty ($ header ) === false ) {
427+
428+ if (is_string ($ header ) === true && $ header !== '' ) {
421429 return $ header ;
422430 }
423431
0 commit comments