-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a custom failure handler feature #30
Conversation
@samdark I specified The example from https://wiki.php.net/rfc/typed_properties_v2#callable_type class Test {
public callable $cb;
public function __construct() {
// $this->cb is callable here
$this->cb = [$this, 'method'];
}
private function method() {}
}
$obj = new Test;
// $obj->cb is NOT callable here
($obj->cb)(); Also see https://stackoverflow.com/questions/57935734/is-type-callable-supported-with-typed-properties @devanych yes, Its convenient that you suggested. But to operate two handlers of |
I don't see anything incorrect here, this is an absolutely standard case. This does not contradict the PSR-15 in any way. |
Ok. Your version is also quite good when dependencies (a session, logger) are needed. I like it. But it is strictly obligatory to create your own class to handle the fail. What if someone doesnt want to create an extra class to handle a fail? Don't think that I'm imagining possible cases, for example I use the Slim microframework and reason based on real needs. |
This is a matter of preference of course. But if I use PSR-15, then it is logical for me to create a separate class that will be responsible for this. And using any microframework would not be a hindrance to me. |
I'd go with $failureHandler = new class() implements \Psr\Http\Server\RequestHandlerInterface {
public function handle(ServerRequestInterface $request): ResponseInterface
{
// return response
}
};
$middleware = new CsrfMiddleware(
$responseFactory,
$token
$token,
$failureHandler
); |
@solventt does that look alright to you? |
Thanks! |
I think it would be nice to let users define their custom failure handler. When a CSRF check fails one may want to do something else besides forming a simple Response, for example, destroy a session, log a CSRF "accident".
But this feature is good if this component is used separately outside of the yii framework. If you take the framework, you have to somehow inject a session and logger instances into the middleware.