/**
* Sets up Twig ready for use and returns it
* @return \Twig_Environment
*/
protected function getTwigEnvironment()
{
/**
* Get the config
* @var \snb\config\ConfigInterface $config
*/
$config = $this->container->get('config');
$kernel = $this->container->get('kernel');
// Find the cache path
$cachePath = $config->get('twig.cache', ':/cache');
// Use our loader the know how to map resource names to filenames
$loader = new TwigFileLoader($this->container);
// use the default environment. Should pass settings over from the config
$twig = new \Twig_Environment($loader, array('cache' => $kernel->findPath($cachePath), 'debug' => $kernel->isDebug()));
// Add the dump command (only works when debug is true)
$twig->addExtension(new \Twig_Extension_Debug());
// Add the app as a global...
$twig->addGlobal('app', $kernel);
// Add all the extensions that have been registered with the service provider
$globals = $this->container->getMatching('twig.global.*');
foreach ($globals as $global) {
if ($global instanceof ViewGlobalInterface) {
$twig->addGlobal($global->getGlobalName(), $global);
}
}
// Add all the extensions that have been registered with the service provider
$extensions = $this->container->getMatching('twig.extension.*');
foreach ($extensions as $ext) {
$twig->addExtension($ext);
}
return $twig;
}