summaryrefslogtreecommitdiff
path: root/src/Renderer/Twig/Extensions/Url.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Renderer/Twig/Extensions/Url.php')
-rw-r--r--src/Renderer/Twig/Extensions/Url.php43
1 files changed, 43 insertions, 0 deletions
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 @@
+<?php
+
+namespace Engelsystem\Renderer\Twig\Extensions;
+
+use Engelsystem\Http\UrlGenerator;
+use Twig_Extension as TwigExtension;
+use Twig_Function as TwigFunction;
+
+class Url extends TwigExtension
+{
+ /** @var UrlGenerator */
+ protected $urlGenerator;
+
+ /**
+ * @param UrlGenerator $urlGenerator
+ */
+ public function __construct(UrlGenerator $urlGenerator)
+ {
+ $this->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);
+ }
+}