From 626334017be21df449f0522b5e32aca833615eaf Mon Sep 17 00:00:00 2001 From: bzick Date: Thu, 9 Jun 2016 14:24:35 +0300 Subject: [PATCH] Small fix of #229 --- src/Fenom.php | 7 ++++--- src/Fenom/Template.php | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Fenom.php b/src/Fenom.php index 20fd6d5..65707b7 100644 --- a/src/Fenom.php +++ b/src/Fenom.php @@ -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; diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index a7624cb..097b7b6 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -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 "_name . "' compiled at " . date('Y-m-d H:i:s') . " */\n" . $before . // some code 'before' template @@ -525,7 +525,7 @@ class Template extends Render $parent = $this->_fenom->getRawTemplate()->load($tpl, false); $parent->blocks = & $this->blocks; $parent->macros = & $this->macros; - $parent->_before = & $this->_before; + $parent->_before = & $this->_before; $parent->extended = $this->getName(); if (!$this->ext_stack) { $this->ext_stack[] = $this->getName(); @@ -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);