Skip to content

Commit a87456d

Browse files
committed
twig extension
1 parent 149991e commit a87456d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Resources/config/services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ services:
1010
gatekeeper.repository.dummy:
1111
class: GateKeeper\Repository\DummyRepository
1212

13+
gatekeeper.twig:
14+
class: GateKeeperBundle\Twig\TwigExtension
15+
arguments: [@gatekeeper]
16+
tags:
17+
- { name: twig.extension }
18+
1319
gatekeeper.access.allow:
1420
public: false
1521
class: %gatekeeper.access.allow.class%

Twig/TwigExtension.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Author: Łukasz Barulski
4+
* Date: 29.04.14 14:17
5+
*/
6+
namespace GateKeeperBundle\Twig;
7+
8+
use GateKeeper\GateKeeper;
9+
10+
class TwigExtension extends \Twig_Extension
11+
{
12+
/**
13+
* @var GateKeeper
14+
*/
15+
private $gateKeeper;
16+
17+
/**
18+
* @param GateKeeper $gateKeeper
19+
*/
20+
public function __construct(GateKeeper $gateKeeper)
21+
{
22+
$this->gateKeeper = $gateKeeper;
23+
}
24+
25+
/**
26+
* @return array
27+
*/
28+
public function getFunctions()
29+
{
30+
return [
31+
new \Twig_SimpleFunction('gate', [$this->gateKeeper, 'hasAccess']),
32+
];
33+
}
34+
35+
/**
36+
* Returns the name of the extension.
37+
* @return string The extension name
38+
*/
39+
public function getName()
40+
{
41+
return 'gatekeeper';
42+
}
43+
}

0 commit comments

Comments
 (0)