From 69c1ff9daab06a5c9f9816c31abf7c21e7f28bf1 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 25 Mar 2014 09:36:25 -0700 Subject: [PATCH] Revert "Reduce Engine constructor complexity." This reverts commit e9d4af3bbefa0088a5125085f49a9fcc02dcd01c. --- src/Mustache/Engine.php | 63 +++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/Mustache/Engine.php b/src/Mustache/Engine.php index f78f375..9eb03d1 100644 --- a/src/Mustache/Engine.php +++ b/src/Mustache/Engine.php @@ -50,23 +50,6 @@ class Mustache_Engine private $parser; private $compiler; - private static $optionProperties = array( - 'template_class_prefix' => 'templateClassPrefix', - 'cache_lambda_templates' => 'cacheLambdaTemplates', - 'escape' => 'escape', - 'entity_flags' => 'entityFlags', - 'charset' => 'charset', - 'strict_callables' => 'strictCallables', - ); - - private static $optionSetters = array( - 'loader' => 'setLoader', - 'partials_loader' => 'setPartialsLoader', - 'partials' => 'setPartials', - 'helpers' => 'setHelpers', - 'logger' => 'setLogger', - ); - /** * Mustache class constructor. * @@ -135,6 +118,10 @@ class Mustache_Engine */ public function __construct(array $options = array()) { + if (isset($options['template_class_prefix'])) { + $this->templateClassPrefix = $options['template_class_prefix']; + } + if (isset($options['cache'])) { $cache = $options['cache']; @@ -146,22 +133,48 @@ class Mustache_Engine $this->setCache($cache); } + if (isset($options['cache_lambda_templates'])) { + $this->cacheLambdaTemplates = (bool) $options['cache_lambda_templates']; + } + + if (isset($options['loader'])) { + $this->setLoader($options['loader']); + } + + if (isset($options['partials_loader'])) { + $this->setPartialsLoader($options['partials_loader']); + } + + if (isset($options['partials'])) { + $this->setPartials($options['partials']); + } + + if (isset($options['helpers'])) { + $this->setHelpers($options['helpers']); + } + if (isset($options['escape'])) { if (!is_callable($options['escape'])) { throw new Mustache_Exception_InvalidArgumentException('Mustache Constructor "escape" option must be callable'); } + + $this->escape = $options['escape']; } - foreach (self::$optionProperties as $name => $property) { - if (isset($options[$name])) { - $this->$property = $options[$name]; - } + if (isset($options['entity_flags'])) { + $this->entityFlags = $options['entity_flags']; } - foreach (self::$optionSetters as $name => $setter) { - if (isset($options[$name])) { - $this->$setter($options[$name]); - } + if (isset($options['charset'])) { + $this->charset = $options['charset']; + } + + if (isset($options['logger'])) { + $this->setLogger($options['logger']); + } + + if (isset($options['strict_callables'])) { + $this->strictCallables = $options['strict_callables']; } }