|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Synapse\Cmf\Framework\Engine\Bridge\Twig; |
|
4
|
|
|
|
|
5
|
|
|
use Synapse\Cmf\Framework\Engine\Renderer\Zone\ZoneRenderer; |
|
6
|
|
|
use Synapse\Cmf\Framework\Engine\Engine as Synapse; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Extension class which provides Synapse specific tags : |
|
10
|
|
|
* - {{ synapse_zone('name') }}. |
|
11
|
|
|
* - {{ synapse_decorate$($decorable, ['param' => 12], 'templateTypeName') }}. |
|
12
|
|
|
*/ |
|
13
|
|
|
class Extension extends \Twig_Extension |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var ZoneRenderer |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $zoneRenderer; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var Synapse |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $synapse; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Construct. |
|
27
|
|
|
* |
|
28
|
|
|
* @param ZoneRenderer $zoneRenderer |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(ZoneRenderer $zoneRenderer, Synapse $synapse) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->zoneRenderer = $zoneRenderer; |
|
33
|
|
|
$this->synapse = $synapse; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @see \Twig_Extension::getName() |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getName() |
|
40
|
|
|
{ |
|
41
|
|
|
return 'synapse'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @see \Twig_Extension::getFunctions() |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getFunctions() |
|
48
|
|
|
{ |
|
49
|
|
|
return array( |
|
50
|
|
|
new \Twig_SimpleFunction('synapse_zone', array($this, 'renderZone'), array('is_safe' => array('html'))), |
|
51
|
|
|
new \Twig_SimpleFunction('synapse_decorate', array($this, 'decorate'), array('is_safe' => array('html'))), |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Render zone under given name. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $name |
|
59
|
|
|
* @param array $parameters |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function renderZone($name, array $parameters = array()) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->zoneRenderer->render($name, $parameters); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Decorates. |
|
70
|
|
|
* |
|
71
|
|
|
* @param ContentInterface|ComponentInterface $decorable |
|
72
|
|
|
* @param array $parameters |
|
73
|
|
|
* @param string $templateTypeName |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public function decorate($decorable, $parameters = array(), $templateTypeName = null) |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->synapse |
|
80
|
|
|
->createDecorator($decorable, $templateTypeName) |
|
81
|
|
|
->decorate($parameters); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|