From 1ce03152822ef49c6311e0798fcff296b9b18fff Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Sun, 1 Dec 2013 19:30:09 +0400 Subject: [PATCH 1/3] 1.4.8 --- CHANGELOG.md | 5 +++++ src/Fenom/Template.php | 9 ++++++++- tests/TestCase.php | 18 ++++++++++++++++++ tests/cases/Fenom/TemplateTest.php | 14 +++++++++++++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abe743e..d46f8fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +### 1.4.8 (2013-12-01) + +- Fix #52 +- Tests++ + ### 1.4.7 (2013-09-19) - Bug fixes diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index ce85a37..fe6f025 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -725,7 +725,14 @@ class Template extends Render if ($this->_options & Fenom::DENY_METHODS) { throw new \LogicException("Forbidden to call methods"); } - $code .= $this->parseArgs($tokens); + do { // parse call-chunks: $var->func()->func()->prop->func()->... + if($tokens->is('(')) { + $code .= $this->parseArgs($tokens); + } + if($tokens->is(T_OBJECT_OPERATOR) && $tokens->isNext(T_STRING)) { + $code .= '->'.$tokens->next()->getAndNext(); + } + } while($tokens->is('(', T_OBJECT_OPERATOR)); } elseif ($tokens->is(Tokenizer::MACRO_INCDEC)) { $code .= $tokens->getAndNext(); } else { diff --git a/tests/TestCase.php b/tests/TestCase.php index 629b495..cedf302 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -274,3 +274,21 @@ class TestCase extends \PHPUnit_Framework_TestCase ); } } + +class Helper { + + public $word = 'helper'; + + public function __construct($word) { + $this->word = $word; + $this->self = $this; + } + + public function chunk() { + return $this; + } + + public function __toString() { + return $this->word; + } +} diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index 04eebaf..e2a2317 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -34,7 +34,18 @@ class TemplateTest extends TestCase $obj->name = "Object"; $obj->list = $a; $obj->c = "c"; - $b = array("b" => array("c" => "Username", "c_char" => "c", "mcp" => "Master", 'm{$c}p' => "Unknown", 'obj' => $obj), "c" => "c"); +// $world = new + $b = array( + "b" => array( + "c" => "Username", + "c_char" => "c", + "mcp" => "Master", + 'm{$c}p' => "Unknown", + 'obj' => $obj + ), + "c" => "c", + "world" => new Helper('world') + ); $c = array_replace_recursive($b, array("b" => array(3 => $b["b"], 4 => "Mister"))); return array( array('hello, {$a}!', $a, 'hello, World!'), @@ -83,6 +94,7 @@ class TemplateTest extends TestCase $b, 'hello, Username!'), array('hello, {"World"}!', $a, 'hello, World!'), array('hello, {"W{$a}d"}!', $a, 'hello, WWorldd!'), + array('hello, {$world->chunk(1)->self->chunk("new")}!', $b, 'hello, world!'), ); } From cd8e8a1bb4184cec5b83b368175f9afc89e3c46b Mon Sep 17 00:00:00 2001 From: evseevnn Date: Sat, 21 Dec 2013 15:19:20 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BD=D1=83=D0=B6=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit В регулярном выражении нет необходимости указывать "^", так как .* заякоривается автоматом. --- src/Fenom/Modifier.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Fenom/Modifier.php b/src/Fenom/Modifier.php index 3da9279..554da90 100644 --- a/src/Fenom/Modifier.php +++ b/src/Fenom/Modifier.php @@ -25,7 +25,7 @@ class Modifier */ public static function dateFormat($date, $format = "%b %e, %Y") { - if (is_string($date) && !is_numeric($date)) { + if (!is_numeric($date)) { $date = strtotime($date); if (!$date) $date = time(); } @@ -39,7 +39,7 @@ class Modifier */ public static function date($date, $format = "Y m d") { - if (is_string($date) && !is_numeric($date)) { + if (!is_numeric($date)) { $date = strtotime($date); if (!$date) $date = time(); } @@ -100,7 +100,7 @@ class Modifier if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) { if (count($match) == 3) { if ($by_words) { - return preg_replace('#\s.*$#usS', "", $match[1]) . $etc . preg_replace('#^.*\s#usS', "", $match[2]); + return preg_replace('#\s.*$#usS', "", $match[1]) . $etc . preg_replace('#.*\s#usS', "", $match[2]); } else { return $match[1] . $etc . $match[2]; } From cf8e25cd8f3675f8b3f000e383c388f07606ebc0 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Wed, 8 Jan 2014 01:05:52 +0400 Subject: [PATCH 3/3] Improve docs --- docs/settings.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/settings.md b/docs/settings.md index a0f8aa7..ba959a7 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -20,16 +20,17 @@ $fenom->setOptions($options); Параметры могут быть массивом `'option_name' => true` (если ключ не указан автоматически задаётся false) или битовой маской. -* **disable_methods**, `Fenom::DENY_METHODS`, disable calling methods in templates. Any method call in the template will throw `Fenom\SecurityException`. -* **disable_native_funcs**, `Fenom::DENY_INLINE_FUNCS`, запретить использование PHP функций, кроме разрешенных. -* **auto_reload**, `Fenom::AUTO_RELOAD`, пересобирать шаблон если его оригинал был изменён (замедляет работу шаблонизатора). -* **force_compile**, `Fenom::FORCE_COMPILE`, пересобирать шаблон при каждом вызове (сильно замедляет работу шаблонизатора). -* **disable_cache**, `Fenom::DISABLE_CACHE`, не сохранять собранный шаблон на диск (сильно замедляет работу шаблонизатора). -* **force_include**, `Fenom::FORCE_INCLUDE`, оптимизировать вставку шаблона в шаблон. Это увеличит производительность и размер собранного шаблона. -Опция активируется если имя шаблона задано явно и скалярно. -* **auto_escape**, `Fenom::AUTO_ESCAPE`, все выводящие переменные и результаты функций будут экранироваться -* **auto_trim**, `Fenom::AUTO_TRIM`, при компиляции, все пробельные символы между тегами будут удлаены. -* **force_verify**, `Fenom::FORCE_VERIFY`, проверять обращение каждой переменной и возвращать NULL если переменной не существует. +| Code | Constant | Description | Affect | +| -------------------- | ------------------------- | ------------ | ------- | +| disable_methods | `Fenom::DENY_METHODS` | disable calling methods of objects in templates. | | +| disable_native_funcs | `Fenom::DENY_INLINE_FUNCS`| disable calling native function in templates, except allowed. | | +| auto_reload | `Fenom::AUTO_RELOAD` | reload template if source will be changed | decreases the performance | +| force_compile | `Fenom::FORCE_COMPILE` | recompile template every time when the template renders | greatly decreases performance | +| disable_cache | `Fenom::DISABLE_CACHE` | disable compile cache | greatly decreases performance | +| force_include | `Fenom::FORCE_INCLUDE` | paste template body instead of include-tag | increases performance, increases cache size | +| auto_escape | `Fenom::AUTO_ESCAPE` | html-escape each variables outputs | decreases performance | +| force_verify | `Fenom::FORCE_VERIFY` | check existence every used variable | decreases performance | +| auto_trim | `Fenom::AUTO_TRIM` | remove space-characters before and after tags | | ```php $fenom->setOptions(array( @@ -40,10 +41,7 @@ $fenom->setOptions(array( $fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_INCLUDE); ``` -По умолчанию, все опции отключены. +**By default all options disabled** ### Tag options -## :raw - -## :trim, :ltrim, :rtrim