Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/Delegates/EnvironmentDelegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ class EnvironmentDelegate implements Hiraeth\Delegate
* @var Hiraeth\Application
*/
protected $app = NULL;


/**
* The Hiraeth configuration instance
*
* @access protected
* @var Hiraeth\Configuration
*/
protected $config = NULL;


/**
* Get the class for which the delegate operates.
*
Expand All @@ -39,8 +39,8 @@ static public function getClass()
{
return 'Twig\Environment';
}


/**
* Get the interfaces for which the delegate provides a class.
*
Expand All @@ -54,8 +54,8 @@ static public function getInterfaces()
'Twig_Environment'
];
}


/**
* Construct the delegate
*
Expand All @@ -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.
*
Expand All @@ -90,15 +90,27 @@ 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()));
} else {
$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;
}
Expand Down