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

Commit

Permalink
Change closure to method for compatibility purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed May 4, 2014
1 parent 29c8237 commit db83835
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 73 deletions.
58 changes: 28 additions & 30 deletions src/SurfStack/Templating/Template_Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,44 +758,42 @@ protected function getRequiredClasses($class)
//return '';
return join(PHP_EOL, array_reverse($arrRequire));
}

public $post;
public $plugrex;

/**
* Replace the plugin tags with PHP code
* @param array $matches
* @return string
*/
protected function dynamicPluginReplacement($matches)
{
$pluginName = $matches[1];
$pluginData = $matches[2];
// Block has content, Slice does not
$pluginContent = (isset($matches[3]) ? "'".addslashes($matches[3])."'" : '');

// Get the variables as a renderable array
$sPassed = $this->buildRenderableArray($this->parsePluginVariables($pluginData));

// Get the requires classes as strings
$require = $this->getRequiredClasses('\SurfStack\Templating\Plugin\\'.$pluginName);

return "<?php $require
\$class = new \SurfStack\Templating\Plugin\\$pluginName();
\$class->store('arrEngineVariables', \$this->variables);
\$class->store('arrEngineInternals', \$this->internal);
\$class->store('arrPluginVariables', $sPassed);
echo \$class->render($pluginContent); ?>";
}

/**
* Replace plugin tags with PHP code
* @param string $content
* @return string
*/
protected function parsePlugins($content)
{
$this->post = false;

//$this->plugrex = array_values($this->loadPlugins());
$this->plugrex = $this->loadPlugins();

{
// Load the plugin content and replace
return preg_replace_callback(array_values($this->plugrex), function($matches) {
$pluginName = $matches[1];
$pluginData = $matches[2];
// Block has content, Slice does not
$pluginContent = (isset($matches[3]) ? "'".addslashes($matches[3])."'" : '');

// Get the variables as a renderable array
$sPassed = $this->buildRenderableArray($this->parsePluginVariables($pluginData));

// Get the requires classes as strings
$require = $this->getRequiredClasses('\SurfStack\Templating\Plugin\\'.$pluginName);

$this->post = true;

return "<?php $require
\$class = new \SurfStack\Templating\Plugin\\$pluginName();
\$class->store('arrEngineVariables', \$this->variables);
\$class->store('arrEngineInternals', \$this->internal);
\$class->store('arrPluginVariables', $sPassed);
echo \$class->render($pluginContent); ?>";
}, $content);
return preg_replace_callback(array_values($this->loadPlugins()), array($this, 'dynamicPluginReplacement') , $content);
}

/**
Expand Down
43 changes: 0 additions & 43 deletions tests/SurfStack/Templating/Template_Engine_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,49 +340,6 @@ public function testVariableBlock()
$this->view->render();
}

public function testPrePost()
{
$this->view->clear();

$this->view->assign('test', 'Hello world');

$this->view->setTemplate('blockVariable.tpl');

$this->view->setLoadPlugins(true);

$this->view->setStripTags(false);

$this->view->setStripWhitespace(false);

$this->render();

$this->assertTrue($this->view->post);
}

public function testPlugRex()
{
$this->view->clear();

$this->view->assign('test', 'Hello world');

$this->view->setTemplate('blockVariable.tpl');

$this->view->setLoadPlugins(true);

$this->view->setStripTags(false);

$this->view->setStripWhitespace(false);

$this->render();

$this->assertSame($this->view->plugrex, array(
'Blank' => '/\{\s*(Blank)\s*(.*?)\}/i',
'Bold' => '/\{\s*(Bold)\s*(.*?)\}(.[^\}\{]*?)\{\/\s*Bold\s*\}/i',
'Passthru' => '/\{\s*(Passthru)\s*(.*?)\}(.[^\}\{]*?)\{\/\s*Passthru\s*\}/i',
'Time' => '/\{\s*(Time)\s*(.*?)\}/i',
));
}

public function testSlice()
{
$this->expectOutputString(date('Y'));
Expand Down

0 comments on commit db83835

Please sign in to comment.