1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Plates\Extension\RenderContext; |
4
|
|
|
|
5
|
|
|
use League\Plates; |
6
|
|
|
|
7
|
|
|
/** The render context extension provides a RenderContext object and functions to be used within the render context object */ |
8
|
|
|
final class RenderContextExtension implements Plates\Extension |
9
|
|
|
{ |
10
|
|
|
public function register(Plates\Engine $plates) { |
11
|
|
|
$c = $plates->getContainer(); |
12
|
|
|
$c->add('renderContext.func', function($c) { |
13
|
|
|
return Plates\Util\stack($c->get('renderContext.func.stack')); |
14
|
|
|
}); |
15
|
|
|
$c->add('renderContext.func.stack', function($c) { |
16
|
|
|
return [ |
17
|
|
|
'plates' => Plates\Util\stackGroup([ |
18
|
|
|
aliasNameFunc($c->get('renderContext.func.aliases')), |
19
|
|
|
splitByNameFunc($c->get('renderContext.func.funcs')) |
20
|
|
|
]) |
21
|
|
|
]; |
22
|
|
|
}); |
23
|
|
|
$c->add('renderContext.func.aliases', [ |
24
|
|
|
'e' => 'escape', |
25
|
|
|
'__invoke' => 'escape', |
26
|
|
|
'stop' => 'end', |
27
|
|
|
]); |
28
|
|
|
$c->add('renderContext.func.funcs', function($c) { |
29
|
|
|
$template_args = assertTemplateArgsFunc(); |
30
|
|
|
$one_arg = assertArgsFunc(1); |
31
|
|
|
$config = $c->get('config'); |
32
|
|
|
|
33
|
|
|
return [ |
34
|
|
|
'insert' => [$template_args, insertFunc()], |
35
|
|
|
'escape' => [ |
36
|
|
|
$one_arg, |
37
|
|
|
isset($config['escape_flags'], $config['escape_encoding']) |
38
|
|
|
? escapeFunc($config['escape_flags'], $config['escape_encoding']) |
39
|
|
|
: escapeFunc() |
40
|
|
|
], |
41
|
|
|
'data' => [accessTemplatePropFunc('data')], |
42
|
|
|
'name' => [accessTemplatePropFunc('name')], |
43
|
|
|
'context' => [accessTemplatePropFunc('context')], |
44
|
|
|
'component' => [$template_args, componentFunc()], |
45
|
|
|
'slot' => [$one_arg, slotFunc()], |
46
|
|
|
'end' => [endFunc()] |
47
|
|
|
]; |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
$c->wrap('compose', function($compose, $c) { |
51
|
|
|
return Plates\Util\compose($compose, renderContextCompose( |
52
|
|
|
$c->get('renderContext.factory'), |
53
|
|
|
$c->get('config')['render_context_var_name'] |
54
|
|
|
)); |
55
|
|
|
}); |
56
|
|
|
$c->add('include.bind', function($c) { |
57
|
|
|
return renderContextBind($c->get('config')['render_context_var_name']); |
58
|
|
|
}); |
59
|
|
|
$c->add('renderContext.factory', function($c) { |
60
|
|
|
return RenderContext::factory( |
61
|
|
|
function() use ($c) { return $c->get('renderTemplate'); }, |
62
|
|
|
$c->get('renderContext.func') |
63
|
|
|
); |
64
|
|
|
}); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|