protected function bootTwig()
    {
        $options = $this->getTwigOptions();
        $options['twig.path'][] = __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views';
        if ($this['debug'] === false) {
            $options['twig.options']['cache'] = $this['app.cache'] . DIRECTORY_SEPARATOR . 'twig';
        }
        $this->register(new TwigServiceProvider(), $options);
        // patch for SF 3.4 break / https://github.com/silexphp/Silex/issues/1579
        $this->extend('twig.runtimes', function ($runtimes, $app) {
            return array_merge($runtimes, [
                FormRenderer::class => 'twig.form.renderer',
            ]);
        });
        $this->extend('twig', function (\Twig_Environment $twig, Application $app) {
            $twig->addExtension(new ImagineExtension($app));
            $twig->addExtension(new ConfigExtension($app));
            return $twig;
        });
    }