paragonie / anti-csrf

Full-Featured Anti-CSRF Library
https://paragonie.com/projects
GNU Affero General Public License v3.0
297 stars 52 forks source link

Make the class instantiable #9

Closed oscarotero closed 8 years ago

oscarotero commented 8 years ago

Hello. I'd like to use this library with psr-7 but because this library relies in global variables $_POST, $_SESSION and $_SERVER, I've changed some static methods of the class to be instantiable. This allows to reuse the library with custom post/session/server parameters. For example:

use ParagonIE\AntiCSRF\AntiCSRF;

//Use the global variables $_POST, $_SESSION and $_SERVER
$csrf = new AntiCSRF();

//Use custom variables
$csrf = new AntiCSRF($request->getParsedBody(), $session, $request->getServerParams());

//check the request
$valid = $csrf->validateRequest();