summaryrefslogtreecommitdiff
path: root/src/Renderer/TwigServiceProvider.php
blob: 238108639bcbf84093fc2d55133584e178639714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

namespace Engelsystem\Renderer;

use Engelsystem\Container\ServiceProvider;
use Twig_Environment as Twig;
use Twig_LoaderInterface as TwigLoaderInterface;

class TwigServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->registerTwigEngine();
    }

    protected function registerTwigEngine()
    {
        $viewsPath = $this->app->get('path.views');

        $twigLoader = $this->app->make(TwigLoader::class, ['paths' => $viewsPath]);
        $this->app->instance(TwigLoader::class, $twigLoader);
        $this->app->instance(TwigLoaderInterface::class, $twigLoader);

        $twig = $this->app->make(Twig::class);
        $this->app->instance(Twig::class, $twig);

        $twigEngine = $this->app->make(TwigEngine::class);
        $this->app->instance('renderer.twigEngine', $twigEngine);
        $this->app->tag('renderer.twigEngine', ['renderer.engine']);
    }
}