Small fix of #229

This commit is contained in:
bzick 2016-06-09 14:24:35 +03:00
parent 24621099bf
commit 626334017b
2 changed files with 10 additions and 7 deletions

View File

@ -7,6 +7,7 @@
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
use Fenom\Error\CompileException;
use Fenom\ProviderInterface;
use Fenom\Template;
@ -1094,7 +1095,7 @@ class Fenom
* @param string|array $tpl
* @param bool $store store template on disk
* @param int $options
* @throws RuntimeException
* @throws CompileException
* @return \Fenom\Template
*/
public function compile($tpl, $store = true, $options = 0)
@ -1111,12 +1112,12 @@ class Fenom
$cache_name = $this->getCompileName($tpl, $options);
$compile_path = $this->_compile_dir . "/" . $cache_name . "." . mt_rand(0, 100000) . ".tmp";
if(!file_put_contents($compile_path, $template->getTemplateCode())) {
throw new \RuntimeException("Can't to write to the file $compile_path. Directory " . $this->_compile_dir . " is writable?");
throw new CompileException("Can't to write to the file $compile_path. Directory " . $this->_compile_dir . " is writable?");
}
$cache_path = $this->_compile_dir . "/" . $cache_name;
if (!rename($compile_path, $cache_path)) {
unlink($compile_path);
throw new \RuntimeException("Can't to move $compile_path to $cache_path");
throw new CompileException("Can't to move the file $compile_path -> $cache_path");
}
}
return $template;

View File

@ -102,7 +102,7 @@ class Template extends Render
*/
private $_ignore = false;
private $_before;
private $_before = array();
private $_filters = array();
@ -310,7 +310,7 @@ class Template extends Render
*/
public function before($code)
{
$this->_before .= $code;
$this->_before[] = $code;
}
/**
@ -405,7 +405,7 @@ class Template extends Render
*/
public function getTemplateCode()
{
$before = $this->_before ? $this->_before . "\n" : "";
$before = $this->_before ? implode("\n", $this->_before) . "\n" : "";
return "<?php \n" .
"/** Fenom template '" . $this->_name . "' compiled at " . date('Y-m-d H:i:s') . " */\n" .
$before . // some code 'before' template
@ -798,12 +798,14 @@ class Template extends Render
}
$code = $this->parseScalar($tokens);
break;
/** @noinspection PhpMissingBreakStatementInspection */
case '$':
$code = $this->parseAccessor($tokens, $is_var);
if(!$is_var) {
$code = $unary . $code;
break;
}
/* no break */
case T_VARIABLE:
if(!isset($code)) {
$code = $this->parseVariable($tokens);