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

Commit

Permalink
Suggested constructor signature changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lexidor committed May 25, 2023
1 parent af6b6ea commit 8c86992
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/router/BaseRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpMethod, KeyedContainer<string, TResponder>>;
Expand All @@ -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<>);
Expand Down
2 changes: 1 addition & 1 deletion src/router/BaseRouterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
namespace Facebook\HackRouter;

type BaseRouterOptions = shape(
'use_get_responder_for_head' => bool,
?'use_get_responder_for_head' => bool,
);

0 comments on commit 8c86992

Please sign in to comment.