<?php
/**
 * Created by PhpStorm.
 * User: eater
 * Date: 4/2/16
 * Time: 3:24 PM
 */

namespace Eater\Glim\Service;


use Eater\Glim\Core;
use Slim\Container;

class Twig
{
    /**
     * @param Container $c
     * @param string $name
     * @return \Twig_Environment
     */
    static public function init($c, $name)
    {
        /** @var Core $core */
        $core = $c->get('core');

        $debug = $core->getConfig()->get('core.debug', false);

        $loader = new \Twig_Loader_Filesystem($core->getBaseDir() . '/views/');
        $twig = new \Twig_Environment($loader, array(
            'cache' => $core->getBaseDir() . '/tmp/twig',
            'debug' => $debug,
            'displayErrorDetails' => $debug
        ));

        if ($twig) {
            $twig->addExtension(new \Twig_Extension_Debug());
        }

        return $twig;
    }
}