1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Container; |
15
|
|
|
use Twig\TwigFilter; |
16
|
|
|
use Twig\TwigFunction; |
17
|
|
|
use WBW\Bundle\CoreBundle\DependencyInjection\ContainerTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Container Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension |
24
|
|
|
*/ |
25
|
|
|
class ContainerTwigExtension extends AbstractTwigExtension { |
26
|
|
|
|
27
|
|
|
use ContainerTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Service name. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
const SERVICE_NAME = "wbw.core.twig.extension.container"; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
* |
39
|
|
|
* @param Container $container The container. |
40
|
|
|
*/ |
41
|
|
|
public function __construct(Container $container) { |
42
|
|
|
$this->setContainer($container); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the Twig filters. |
47
|
|
|
* |
48
|
|
|
* @return TwigFilter[] Returns the Twig filters. |
49
|
|
|
*/ |
50
|
|
|
public function getFilters() { |
51
|
|
|
return []; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get the Twig functions. |
56
|
|
|
* |
57
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
58
|
|
|
*/ |
59
|
|
|
public function getFunctions() { |
60
|
|
|
return [ |
61
|
|
|
new TwigFunction("getContainerParameter", [$this, "getContainerParameterFunction"]), |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get a container parameter. |
67
|
|
|
* |
68
|
|
|
* @param string $name The name. |
69
|
|
|
* @return mixed|null Returns the container parameter in case of success, null otherwise. |
70
|
|
|
*/ |
71
|
|
|
public function getContainerParameterFunction($name) { |
72
|
|
|
return $this->getContainer()->getParameter($name); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|