Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 8c86992

Browse files
committed
Suggested constructor signature changes
1 parent af6b6ea commit 8c86992

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/router/BaseRouter.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
use function Facebook\AutoloadMap\Generated\is_dev;
1515

1616
abstract class BaseRouter<+TResponder> {
17-
public function __construct(
18-
private BaseRouterOptions $options = shape('use_get_responder_for_head' => true)
19-
) {}
17+
private bool $useGetResponderForHead;
18+
19+
public function __construct(?BaseRouterOptions $options = null) {
20+
$this->useGetResponderForHead =
21+
Shapes::idx($options, 'use_get_responder_for_head', true);
22+
}
2023

2124
abstract protected function getRoutes(
2225
): KeyedContainer<HttpMethod, KeyedContainer<string, TResponder>>;
@@ -37,7 +40,9 @@ final public function routeMethodAndPath(
3740
}
3841

3942
if (
40-
$this->options['use_get_responder_for_head'] && $method === HttpMethod::HEAD && $allowed === keyset[HttpMethod::GET]
43+
$this->useGetResponderForHead &&
44+
$method === HttpMethod::HEAD &&
45+
$allowed === keyset[HttpMethod::GET]
4146
) {
4247
list($responder, $data) = $resolver->resolve(HttpMethod::GET, $path);
4348
$data = Dict\map($data, \urldecode<>);

src/router/BaseRouterOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
namespace Facebook\HackRouter;
1313

1414
type BaseRouterOptions = shape(
15-
'use_get_responder_for_head' => bool,
15+
?'use_get_responder_for_head' => bool,
1616
);

0 commit comments

Comments
 (0)