From f42e3e2c14e3d7d1d46128908d7b0530b32745b1 Mon Sep 17 00:00:00 2001 From: Kerri Cranwell Date: Wed, 30 Aug 2017 17:35:26 -0400 Subject: [PATCH] Update EnvironmentDelegate --- src/Delegates/EnvironmentDelegate.php | 36 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Delegates/EnvironmentDelegate.php b/src/Delegates/EnvironmentDelegate.php index 28c0ca4..11dbec3 100644 --- a/src/Delegates/EnvironmentDelegate.php +++ b/src/Delegates/EnvironmentDelegate.php @@ -17,8 +17,8 @@ class EnvironmentDelegate implements Hiraeth\Delegate * @var Hiraeth\Application */ protected $app = NULL; - - + + /** * The Hiraeth configuration instance * @@ -26,8 +26,8 @@ class EnvironmentDelegate implements Hiraeth\Delegate * @var Hiraeth\Configuration */ protected $config = NULL; - - + + /** * Get the class for which the delegate operates. * @@ -39,8 +39,8 @@ static public function getClass() { return 'Twig\Environment'; } - - + + /** * Get the interfaces for which the delegate provides a class. * @@ -54,8 +54,8 @@ static public function getInterfaces() 'Twig_Environment' ]; } - - + + /** * Construct the delegate * @@ -69,8 +69,8 @@ public function __construct(Hiraeth\Application $app, Hiraeth\Configuration $con $this->app = $app; $this->config = $config; } - - + + /** * Get the instance of the class for which the delegate operates. * @@ -90,8 +90,12 @@ public function __invoke(Hiraeth\Broker $broker) ? $this->app->getDirectory($cache_path) : FALSE ]); - - foreach ($this->config->get('*', 'twig.filters', array()) as $config => $filters) { + + foreach (array_keys($this->config->get('*', 'twig', array())) as $config) { + $filters = $this->config->get($config, 'twig.filters', array()); + $globals = $this->config->get($config, 'twig.globals', array()); + $extensions = $this->config->get($config, 'twig.extensions', array()); + foreach ($filters as $name => $filter) { if (function_exists($filter['target'])) { $environment->addFilter(new Twig\TwigFilter($name, $filter['target'], $filter['options'] ?? array())); @@ -99,6 +103,14 @@ public function __invoke(Hiraeth\Broker $broker) $environment->addFilter(new Twig\TwigFilter($name, new $filter['target'], $filter['options'] ?? array())); } } + + foreach ($globals as $name => $class) { + $environment->addGlobal($name, $broker->make($class)); + } + + foreach ($extensions as $class) { + $environment->addExtension($broker->make($class)); + } } return $environment; }