diff --git a/src/SurfStack/Templating/Template_Engine.php b/src/SurfStack/Templating/Template_Engine.php index 41cb3e5..6b2df44 100644 --- a/src/SurfStack/Templating/Template_Engine.php +++ b/src/SurfStack/Templating/Template_Engine.php @@ -52,6 +52,8 @@ function __construct($path, $template) 'CacheTemplates' => false, 'CacheLifetime' => 3600, 'AlwaysCheckOriginal' => false, + 'PluginCount' => 0, + 'PluginsLoaded' => array(), ); $this->setTemplateDir($path); @@ -102,6 +104,26 @@ protected function setInternal($key, $value) $this->internal[$key] = $value; } + /** + * Increment internal variable + * @param string $key + * @param int $int + */ + protected function incrementInternal($key, $int = 1) + { + $this->internal[$key] += intval($int); + } + + /** + * Added to internal variable array + * @param string $key + * @param string $value + */ + protected function pushInternal($key, $value) + { + $this->internal[$key][] = $value; + } + /** * Set all the internal variables * @param array $arr @@ -607,6 +629,9 @@ protected function loadPlugins() { if ($this->getInternal('PluginDir')) { + $this->setInternal('PluginCount', 0); + $this->setInternal('PluginsLoaded', array()); + foreach(glob($this->getInternal('PluginDir').'/*.php') as $file) { require_once $file; @@ -624,6 +649,9 @@ protected function loadPlugins() $return[$name] = '/\{\s*('.$name.')\s*(.*?)\}/i'; break; } + + $this->incrementInternal('PluginCount'); + $this->pushInternal('PluginsLoaded', $name); } } } @@ -631,6 +659,24 @@ protected function loadPlugins() return $return; } + /** + * Get an array of loaded plugins + * @return array + */ + public function getLoadedPlugins() + { + return $this->getInternal('PluginsLoaded'); + } + + /** + * Get the number of loaded plugins + * @return int + */ + public function getNumberLoadedPlugins() + { + return $this->getInternal('PluginCount'); + } + /** * Build an array that can be rendered * @param array $arr diff --git a/tests/SurfStack/Templating/Template_Engine_Test.php b/tests/SurfStack/Templating/Template_Engine_Test.php index 9af9214..a16f88d 100644 --- a/tests/SurfStack/Templating/Template_Engine_Test.php +++ b/tests/SurfStack/Templating/Template_Engine_Test.php @@ -298,6 +298,29 @@ public function testBlock() $this->view->render(); } + public function testLoadPluginsArray() + { + $this->view->setLoadPlugins(true); + + $this->render(); + + $this->assertSame($this->view->getLoadedPlugins(), array( + 'Blank', + 'Bold', + 'Passthru', + 'Time', + )); + } + + public function testLoadPluginsCount() + { + $this->view->setLoadPlugins(true); + + $this->render(); + + $this->assertSame($this->view->getNumberLoadedPlugins(), 4); + } + public function testVariableBlock() { $this->expectOutputString('Hello world.');