-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathYesWikiController.php
52 lines (43 loc) · 1.25 KB
/
YesWikiController.php
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
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace YesWiki\Core;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use YesWiki\Core\Service\AclService;
use YesWiki\Core\Service\TemplateEngine;
use YesWiki\Wiki;
abstract class YesWikiController
{
protected $wiki;
/**
* Setter for the wiki property.
*
* @Required set the auto-injection
*/
public function setWiki(Wiki $wiki): void
{
$this->wiki = $wiki;
}
protected function render($templatePath, $data = [], $method = 'render')
{
return $this->wiki->services->get(TemplateEngine::class)->$method($templatePath, $data);
}
protected function renderInSquelette($templatePath, $data = [])
{
return $this->render($templatePath, $data, 'renderInSquelette');
}
protected function denyAccessUnlessGranted($role, $tag)
{
if (!$this->getService(AclService::class)->hasAccess($role, $tag)) {
throw new AccessDeniedHttpException();
}
}
protected function denyAccessUnlessAdmin()
{
if (!$this->wiki->UserIsAdmin()) {
throw new AccessDeniedHttpException();
}
}
protected function getService($className)
{
return $this->wiki->services->get($className);
}
}