From 4ba15033d9d1f1c0a0266e287016bc90cb54a164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sat, 9 Sep 2017 01:40:44 +0100 Subject: [PATCH] Readded csrf_token helper function - don't run away this time. --- README.md | 26 ++++++++++++++++++++------ helpers.php | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3375724..edfab1d 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,8 @@ We recommend that you add these helper functions to your project. These will all To implement the functions below, simply copy the code to a new file and require the file before initializing the router or copy the `helpers.php` we've included in this library. ```php -getInput()->get($index, $defaultValue, $methods); } @@ -313,6 +313,20 @@ function redirect($url, $code = null) response()->redirect($url); } + +/** + * Get current csrf-token + * @return string|null + */ +function csrf_token() +{ + $baseVerifier = Router::router()->getCsrfVerifier(); + if ($baseVerifier !== null) { + return $baseVerifier->getToken(); + } + + return null; +} ``` --- diff --git a/helpers.php b/helpers.php index d0e6e04..2c5c1c4 100644 --- a/helpers.php +++ b/helpers.php @@ -63,4 +63,18 @@ function redirect($url, $code = null) } response()->redirect($url); +} + +/** + * Get current csrf-token + * @return string|null + */ +function csrf_token() +{ + $baseVerifier = Router::router()->getCsrfVerifier(); + if ($baseVerifier !== null) { + return $baseVerifier->getToken(); + } + + return null; } \ No newline at end of file