Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Added plugin gathering information
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed May 3, 2014
1 parent 30811f3 commit 9cc8e26
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/SurfStack/Templating/Template_Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function __construct($path, $template)
'CacheTemplates' => false,
'CacheLifetime' => 3600,
'AlwaysCheckOriginal' => false,
'PluginCount' => 0,
'PluginsLoaded' => array(),
);

$this->setTemplateDir($path);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -624,13 +649,34 @@ protected function loadPlugins()
$return[$name] = '/\{\s*('.$name.')\s*(.*?)\}/i';
break;
}

$this->incrementInternal('PluginCount');
$this->pushInternal('PluginsLoaded', $name);
}
}
}

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
Expand Down
23 changes: 23 additions & 0 deletions tests/SurfStack/Templating/Template_Engine_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down

0 comments on commit 9cc8e26

Please sign in to comment.