blob: 6a72d825068af2101b47b23483fac1300b723663 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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);
}
}
|