Skip to content

Commit

Permalink
Allow constructing Blitz without a filename argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuelenaere committed Jul 18, 2015
1 parent bc240f1 commit a06018d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $assignments = [
];

// construct Blitz object
$blitz = new Plitz\Bindings\Blitz\Blitz(null);
$blitz = new Plitz\Bindings\Blitz\Blitz();

// load template
$blitz->load($template);
Expand Down
13 changes: 9 additions & 4 deletions src/Bindings/Blitz/Blitz.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Blitz
/**
* Template filename
*
* @var string
* @var string|null
*/
private $templatePath;

Expand All @@ -49,7 +49,7 @@ class Blitz
*/
private $iterations;

public function __construct($filename, $templateRoot = null)
public function __construct($filename = null, $templateRoot = null)
{
/*
* INI settings:
Expand Down Expand Up @@ -86,7 +86,9 @@ public function __construct($filename, $templateRoot = null)
$this->globalVariables = [];
$this->iterations = [];
$this->templateRoot = rtrim($templateRoot, DIRECTORY_SEPARATOR);
$this->templatePath = $this->templateRoot . DIRECTORY_SEPARATOR . $filename;
if ($filename !== null) {
$this->templatePath = $this->templateRoot . DIRECTORY_SEPARATOR . $filename;
}
$this->compiledTemplatePath = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'plitz' . DIRECTORY_SEPARATOR . $filename . '.php';
}

Expand Down Expand Up @@ -248,7 +250,10 @@ public function parse(array $iterations = [])
public function display(array $iterations = [])
{
// TODO: disable this check in production
if (!is_file($this->compiledTemplatePath) || filemtime($this->templatePath) >= filemtime($this->compiledTemplatePath)) {
if (
!is_file($this->compiledTemplatePath)
|| ($this->templatePath !== null && filemtime($this->templatePath) >= filemtime($this->compiledTemplatePath))
) {
if (!is_dir(dirname($this->compiledTemplatePath))) {
// recursively create parent directories
mkdir(dirname($this->compiledTemplatePath), 0755, true);
Expand Down

0 comments on commit a06018d

Please sign in to comment.