|
@@ -0,0 +1,43 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace demo\Services;
|
|
|
+
|
|
|
+use Silex\Application;
|
|
|
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
+
|
|
|
+class NavBuilder {
|
|
|
+
|
|
|
+
|
|
|
+ * @var \Twig_Environment
|
|
|
+ */
|
|
|
+ protected $twig;
|
|
|
+
|
|
|
+
|
|
|
+ * @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface
|
|
|
+ */
|
|
|
+ protected $urlGenerator;
|
|
|
+
|
|
|
+ public function __construct(
|
|
|
+ UrlGeneratorInterface $urlGenerator,
|
|
|
+ \Twig_Environment $twig
|
|
|
+ ) {
|
|
|
+ $this->twig = $twig;
|
|
|
+ $this->urlGenerator = $urlGenerator;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function create(Application $app) {
|
|
|
+ $urlGenerator = $app['url_generator'];
|
|
|
+ $twig = $app['twig'];
|
|
|
+ return new static($urlGenerator, $twig);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function build() {
|
|
|
+ $home = $this->urlGenerator->generate('homepage');
|
|
|
+ $blog = $this->urlGenerator->generate('blog_list');
|
|
|
+ $result = [
|
|
|
+ 'home' => ['url' => $home, 'text' => 'Accueil'],
|
|
|
+ 'blog' => ['url' => $blog, 'text' => 'Blogs'],
|
|
|
+ ];
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+}
|