diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-23 19:13:19 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-23 20:11:37 +0200 |
commit | 66038eda14d5d4e624b6636a6156570e3e940e49 (patch) | |
tree | 6e4b7557b7d91786ef47f22f7ddef85eed1dfb42 /src/Renderer/Twig/Extensions/Authentication.php | |
parent | 590adffa9316b98544cb8d67b03b80e44ba9c8b7 (diff) | |
parent | 9d34f371cb9c5ab0d60bd3158678b9cc9da6cc80 (diff) |
Merge branch 'twig-templates'
Diffstat (limited to 'src/Renderer/Twig/Extensions/Authentication.php')
-rw-r--r-- | src/Renderer/Twig/Extensions/Authentication.php | 40 |
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); + } +} |