1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the CRUDlexSilex2 package. |
4
|
|
|
* |
5
|
|
|
* (c) Philip Lehmann-Böhm <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace CRUDlex\Silex; |
12
|
|
|
|
13
|
|
|
use CRUDlex\TwigExtensions; |
14
|
|
|
use Pimple\Container; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Provides and setups the Twig extensions like filters for Silex. |
18
|
|
|
*/ |
19
|
|
|
class TwigSetup |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Registers all extensions. |
24
|
|
|
* |
25
|
|
|
* @param Container $app |
26
|
|
|
* the current application |
27
|
|
|
*/ |
28
|
|
|
public function registerTwigExtensions(Container $app) |
29
|
|
|
{ |
30
|
|
|
$twigExtensions = new TwigExtensions(); |
31
|
|
|
$app->extend('twig', function(\Twig_Environment $twig) use ($twigExtensions, $app) { |
32
|
|
|
$twig->addFilter(new \Twig_SimpleFilter('crudlex_arrayColumn', 'array_column')); |
33
|
|
|
$twig->addFilter(new \Twig_SimpleFilter('crudlex_languageName', [$twigExtensions, 'getLanguageName'])); |
34
|
|
|
$twig->addFilter(new \Twig_SimpleFilter('crudlex_float', [$twigExtensions, 'formatFloat'])); |
35
|
|
|
$twig->addFilter(new \Twig_SimpleFilter('crudlex_basename', 'basename')); |
36
|
|
|
$twig->addFilter(new \Twig_SimpleFilter('crudlex_formatDate', [$twigExtensions, 'formatDate'])); |
37
|
|
|
$twig->addFilter(new \Twig_SimpleFilter('crudlex_formatDateTime', [$twigExtensions, 'formatDateTime'])); |
38
|
|
|
$twig->addFunction(new \Twig_SimpleFunction('crudlex_getCurrentUri', function() use ($app) { |
39
|
|
|
return $app['request_stack']->getCurrentRequest()->getUri(); |
40
|
|
|
})); |
41
|
|
|
$twig->addFunction(new \Twig_SimpleFunction('crudlex_sessionGet', function($name, $default) use ($app) { |
42
|
|
|
return $app['session']->get($name, $default); |
43
|
|
|
})); |
44
|
|
|
$twig->addFunction(new \Twig_SimpleFunction('crudlex_sessionFlashBagGet', function($type) use ($app) { |
45
|
|
|
return $app['session']->getFlashBag()->get($type); |
46
|
|
|
})); |
47
|
|
|
return $twig; |
48
|
|
|
}); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|