Skip to content

Commit

Permalink
Updated Template\Renderer.php
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Jan 6, 2016
1 parent bd39610 commit 4662b45
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions src/Template/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,17 @@ public function __construct(array $directories)
*
* @param string $template
* @param array $data
* @param boolean $toString
* @return string
*/
public function render($template, array $data = [], $toString = false)
public function render($template, array $data = [])
{
$file = $this->getTemplate("$template.php");

// Extracts the specific parameters to the template.
if ($data) {
if ( ! empty($data)) {
extract($data);
}

// Buffers the file and get its output, else include the file
if ($toString) {
return $this->toString($file);
}

include $file;
}

Expand Down Expand Up @@ -87,27 +81,4 @@ private function getTemplate($template)

return new InvalidArgumentException('Template file not found.');
}

/**
* Returns the output to string.
*
* @param string $file
* @return string
*/
private function toString($file)
{
ob_start();

$fileContents = file_get_contents($file);
$removedTags = str_replace('<?=', '<?php echo ', $fileContents);
$result = preg_replace('/;*\s*\?>/', '; ?>', $removedTags);

echo eval('?>' . $result);

$result = ob_get_contents();

ob_end_clean();

return $result;
}
}

0 comments on commit 4662b45

Please sign in to comment.