From df6360044b5c2396b2bee0dfa9e8d744bfa424d5 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 26 Aug 2018 12:23:47 +0200 Subject: Added Twig template functions --- src/Renderer/Twig/Extensions/Config.php | 31 +++++++++++++++++++++++ src/Renderer/Twig/Extensions/Globals.php | 23 +++++++++++++++++ src/Renderer/Twig/Extensions/Session.php | 31 +++++++++++++++++++++++ src/Renderer/Twig/Extensions/Url.php | 43 ++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/Renderer/Twig/Extensions/Config.php create mode 100644 src/Renderer/Twig/Extensions/Globals.php create mode 100644 src/Renderer/Twig/Extensions/Session.php create mode 100644 src/Renderer/Twig/Extensions/Url.php (limited to 'src/Renderer/Twig') diff --git a/src/Renderer/Twig/Extensions/Config.php b/src/Renderer/Twig/Extensions/Config.php new file mode 100644 index 00000000..dbbe93e7 --- /dev/null +++ b/src/Renderer/Twig/Extensions/Config.php @@ -0,0 +1,31 @@ +config = $config; + } + + /** + * @return TwigFunction[] + */ + public function getFunctions() + { + return [ + new TwigFunction('config', [$this->config, 'get']), + ]; + } +} diff --git a/src/Renderer/Twig/Extensions/Globals.php b/src/Renderer/Twig/Extensions/Globals.php new file mode 100644 index 00000000..f9bffbc8 --- /dev/null +++ b/src/Renderer/Twig/Extensions/Globals.php @@ -0,0 +1,23 @@ + isset($user) ? $user : [], + ]; + } +} diff --git a/src/Renderer/Twig/Extensions/Session.php b/src/Renderer/Twig/Extensions/Session.php new file mode 100644 index 00000000..4690f701 --- /dev/null +++ b/src/Renderer/Twig/Extensions/Session.php @@ -0,0 +1,31 @@ +session = $session; + } + + /** + * @return TwigFunction[] + */ + public function getFunctions() + { + return [ + new TwigFunction('session_get', [$this->session, 'get']), + ]; + } +} diff --git a/src/Renderer/Twig/Extensions/Url.php b/src/Renderer/Twig/Extensions/Url.php new file mode 100644 index 00000000..62e59782 --- /dev/null +++ b/src/Renderer/Twig/Extensions/Url.php @@ -0,0 +1,43 @@ +urlGenerator = $urlGenerator; + } + + /** + * @return TwigFunction[] + */ + public function getFunctions() + { + return [ + new TwigFunction('url', [$this, 'getUrl']), + ]; + } + + /** + * @param string $path + * @param array $parameters + * @return UrlGenerator|string + */ + public function getUrl($path, $parameters = []) + { + $path = str_replace('_', '-', $path); + + return $this->urlGenerator->to($path, $parameters); + } +} -- cgit v1.2.3-54-g00ecf