From 8c869923f4c84d47e9b3dc3a174e8463b863e02d Mon Sep 17 00:00:00 2001 From: Lexidor Digital <31805625+lexidor@users.noreply.github.com> Date: Thu, 25 May 2023 21:08:58 +0200 Subject: [PATCH] Suggested constructor signature changes --- src/router/BaseRouter.php | 13 +++++++++---- src/router/BaseRouterOptions.php | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/router/BaseRouter.php b/src/router/BaseRouter.php index 109b5e1..abed131 100644 --- a/src/router/BaseRouter.php +++ b/src/router/BaseRouter.php @@ -14,9 +14,12 @@ use function Facebook\AutoloadMap\Generated\is_dev; abstract class BaseRouter<+TResponder> { - public function __construct( - private BaseRouterOptions $options = shape('use_get_responder_for_head' => true) - ) {} + private bool $useGetResponderForHead; + + public function __construct(?BaseRouterOptions $options = null) { + $this->useGetResponderForHead = + Shapes::idx($options, 'use_get_responder_for_head', true); + } abstract protected function getRoutes( ): KeyedContainer>; @@ -37,7 +40,9 @@ final public function routeMethodAndPath( } if ( - $this->options['use_get_responder_for_head'] && $method === HttpMethod::HEAD && $allowed === keyset[HttpMethod::GET] + $this->useGetResponderForHead && + $method === HttpMethod::HEAD && + $allowed === keyset[HttpMethod::GET] ) { list($responder, $data) = $resolver->resolve(HttpMethod::GET, $path); $data = Dict\map($data, \urldecode<>); diff --git a/src/router/BaseRouterOptions.php b/src/router/BaseRouterOptions.php index de0281f..63158a9 100644 --- a/src/router/BaseRouterOptions.php +++ b/src/router/BaseRouterOptions.php @@ -12,5 +12,5 @@ namespace Facebook\HackRouter; type BaseRouterOptions = shape( - 'use_get_responder_for_head' => bool, + ?'use_get_responder_for_head' => bool, );