summaryrefslogtreecommitdiff
path: root/src/Renderer/Twig/Extensions/Authentication.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-02 02:09:56 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-02 02:09:56 +0200
commit9e217d87c095170460a8580d5215ddf7cbe639f4 (patch)
tree3b426fe52e70ef0f1395edcb354f1be4788ca329 /src/Renderer/Twig/Extensions/Authentication.php
parentac48332166ce28fcb1a2fc130c7f5adbc760e42d (diff)
Template refactoring to use twig
Diffstat (limited to 'src/Renderer/Twig/Extensions/Authentication.php')
-rw-r--r--src/Renderer/Twig/Extensions/Authentication.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Renderer/Twig/Extensions/Authentication.php b/src/Renderer/Twig/Extensions/Authentication.php
new file mode 100644
index 00000000..6a72d825
--- /dev/null
+++ b/src/Renderer/Twig/Extensions/Authentication.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Engelsystem\Renderer\Twig\Extensions;
+
+use Twig_Extension as TwigExtension;
+use Twig_Function as TwigFunction;
+
+class Authentication extends TwigExtension
+{
+ /**
+ * @return TwigFunction[]
+ */
+ public function getFunctions()
+ {
+ return [
+ new TwigFunction('is_user', [$this, 'isAuthenticated']),
+ new TwigFunction('is_guest', [$this, 'isGuest']),
+ new TwigFunction('has_permission_to', [$this, 'checkAuth']),
+ ];
+ }
+
+ public function isAuthenticated()
+ {
+ global $user;
+
+ return !empty($user);
+ }
+
+ public function isGuest()
+ {
+ return !$this->isAuthenticated();
+ }
+
+ public function checkAuth($privilege)
+ {
+ global $privileges;
+
+ return in_array($privilege, $privileges);
+ }
+}