Replies: 1 comment 4 replies
-
This is especially useful when the api key, in this case, is not part of the controller logic but instead, the repository logic. Since repositories are injected via DI, it would be nice to be able to also then inject the API key into their container block and pass into the constructor, for example: $container = new Container([
ApiKey::class => function(ServerRequestInterface $request) {
$headerLine = $request->getHeaderLine("API-Key");
assert(is_string($headerLine);
return ApiKey::fromString($headerLine);
},
SomeRepositoryInterface::class => function(ApiKey $apiKey, ...) {
return new SomeRepository($apiKey, ...);
}
]); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As the container is just middleware, it would be nice to have the ServerRequestInterface for the request being injectable when required.
I personally would like to do something like the following:
Currently if I do this though, it throws a 500 and does not propagate the ServerRequestInterface through to the next middleware it seems.
Beta Was this translation helpful? Give feedback.
All reactions