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

Commit

Permalink
Replace static local with a a caching mechanism that actually works
Browse files Browse the repository at this point in the history
It was never initialized :/ whoops
  • Loading branch information
fredemmott committed Mar 26, 2019
1 parent a8c2ce9 commit d22d3e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions .hhconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ decl_override_require_hint=true
enable_experimental_tc_features=shape_field_check,sealed_classes
user_attributes=
disable_primitive_refinement=true
disable_static_local_variables = true
32 changes: 16 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/router/BaseRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ final public function routeRequest(
return $this->routeMethodAndPath($method, $request->getUri()->getPath());
}

private ?IResolver<TResponder> $resolver = null;

protected function getResolver(): IResolver<TResponder> {
// Don't use <<__Memoize>> because that can be surprising with subclassing
static $resolver = null;
if ($resolver !== null) {
return $resolver;
if ($this->resolver !== null) {
return $this->resolver;
}

if (is_dev()) {
Expand All @@ -84,6 +84,7 @@ protected function getResolver(): IResolver<TResponder> {
\apc_store(__FILE__.'/cache', $routes);
}
}
return new PrefixMatchingResolver($routes);
$this->resolver = new PrefixMatchingResolver($routes);
return $this->resolver;
}
}

0 comments on commit d22d3e2

Please sign in to comment.