mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
Merge branch 'origin/master'
Conflicts: CHANGELOG.md
This commit is contained in:
commit
19e0898da6
|
@ -12,6 +12,11 @@ Changelog
|
||||||
- Move benchmark to another project
|
- Move benchmark to another project
|
||||||
- Rename `\Fenom\Compiler` to `\Fenom\Tags`
|
- Rename `\Fenom\Compiler` to `\Fenom\Tags`
|
||||||
|
|
||||||
|
### 1.4.8 (2013-12-01)
|
||||||
|
|
||||||
|
- Fix #52
|
||||||
|
- Tests++
|
||||||
|
|
||||||
### 1.4.7 (2013-09-21)
|
### 1.4.7 (2013-09-21)
|
||||||
|
|
||||||
- Bug fixes
|
- Bug fixes
|
||||||
|
|
|
@ -20,16 +20,17 @@ $fenom->setOptions($options);
|
||||||
|
|
||||||
Параметры могут быть массивом `'option_name' => true` (если ключ не указан автоматически задаётся false) или битовой маской.
|
Параметры могут быть массивом `'option_name' => true` (если ключ не указан автоматически задаётся false) или битовой маской.
|
||||||
|
|
||||||
* **disable_methods**, `Fenom::DENY_METHODS`, disable calling methods in templates. Any method call in the template will throw `Fenom\SecurityException`.
|
| Code | Constant | Description | Affect |
|
||||||
* **disable_native_funcs**, `Fenom::DENY_INLINE_FUNCS`, запретить использование PHP функций, кроме разрешенных.
|
| -------------------- | ------------------------- | ------------ | ------- |
|
||||||
* **auto_reload**, `Fenom::AUTO_RELOAD`, пересобирать шаблон если его оригинал был изменён (замедляет работу шаблонизатора).
|
| disable_methods | `Fenom::DENY_METHODS` | disable calling methods of objects in templates. | |
|
||||||
* **force_compile**, `Fenom::FORCE_COMPILE`, пересобирать шаблон при каждом вызове (сильно замедляет работу шаблонизатора).
|
| disable_native_funcs | `Fenom::DENY_INLINE_FUNCS`| disable calling native function in templates, except allowed. | |
|
||||||
* **disable_cache**, `Fenom::DISABLE_CACHE`, не сохранять собранный шаблон на диск (сильно замедляет работу шаблонизатора).
|
| auto_reload | `Fenom::AUTO_RELOAD` | reload template if source will be changed | decreases the performance |
|
||||||
* **force_include**, `Fenom::FORCE_INCLUDE`, оптимизировать вставку шаблона в шаблон. Это увеличит производительность и размер собранного шаблона.
|
| 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 |
|
||||||
* **auto_escape**, `Fenom::AUTO_ESCAPE`, все выводящие переменные и результаты функций будут экранироваться
|
| force_include | `Fenom::FORCE_INCLUDE` | paste template body instead of include-tag | increases performance, increases cache size |
|
||||||
* **auto_trim**, `Fenom::AUTO_TRIM`, при компиляции, все пробельные символы между тегами будут удлаены.
|
| auto_escape | `Fenom::AUTO_ESCAPE` | html-escape each variables outputs | decreases performance |
|
||||||
* **force_verify**, `Fenom::FORCE_VERIFY`, проверять обращение каждой переменной и возвращать NULL если переменной не существует.
|
| 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
|
```php
|
||||||
$fenom->setOptions(array(
|
$fenom->setOptions(array(
|
||||||
|
@ -40,10 +41,7 @@ $fenom->setOptions(array(
|
||||||
$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_INCLUDE);
|
$fenom->setOptions(Fenom::AUTO_RELOAD | Fenom::FORCE_INCLUDE);
|
||||||
```
|
```
|
||||||
|
|
||||||
По умолчанию, все опции отключены.
|
**By default all options disabled**
|
||||||
|
|
||||||
### Tag options
|
### Tag options
|
||||||
|
|
||||||
## :raw
|
|
||||||
|
|
||||||
## :trim, :ltrim, :rtrim
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Modifier
|
||||||
*/
|
*/
|
||||||
public static function dateFormat($date, $format = "%b %e, %Y")
|
public static function dateFormat($date, $format = "%b %e, %Y")
|
||||||
{
|
{
|
||||||
if (is_string($date) && !is_numeric($date)) {
|
if (!is_numeric($date)) {
|
||||||
$date = strtotime($date);
|
$date = strtotime($date);
|
||||||
if (!$date) $date = time();
|
if (!$date) $date = time();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class Modifier
|
||||||
*/
|
*/
|
||||||
public static function date($date, $format = "Y m d")
|
public static function date($date, $format = "Y m d")
|
||||||
{
|
{
|
||||||
if (is_string($date) && !is_numeric($date)) {
|
if (!is_numeric($date)) {
|
||||||
$date = strtotime($date);
|
$date = strtotime($date);
|
||||||
if (!$date) $date = time();
|
if (!$date) $date = time();
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ class Modifier
|
||||||
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
|
if (preg_match('#^(.{' . $length . '}).*?(.{' . $length . '})?$#usS', $string, $match)) {
|
||||||
if (count($match) == 3) {
|
if (count($match) == 3) {
|
||||||
if ($by_words) {
|
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 {
|
} else {
|
||||||
return $match[1] . $etc . $match[2];
|
return $match[1] . $etc . $match[2];
|
||||||
}
|
}
|
||||||
|
|
|
@ -732,7 +732,14 @@ class Template extends Render
|
||||||
if ($this->_options & Fenom::DENY_METHODS) {
|
if ($this->_options & Fenom::DENY_METHODS) {
|
||||||
throw new \LogicException("Forbidden to call 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)) {
|
} elseif ($tokens->is(Tokenizer::MACRO_INCDEC)) {
|
||||||
$code .= $tokens->getAndNext();
|
$code .= $tokens->getAndNext();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -34,7 +34,18 @@ class TemplateTest extends TestCase
|
||||||
$obj->name = "Object";
|
$obj->name = "Object";
|
||||||
$obj->list = $a;
|
$obj->list = $a;
|
||||||
$obj->c = "c";
|
$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")));
|
$c = array_replace_recursive($b, array("b" => array(3 => $b["b"], 4 => "Mister")));
|
||||||
return array(
|
return array(
|
||||||
array('hello, {$a}!', $a, 'hello, World!'),
|
array('hello, {$a}!', $a, 'hello, World!'),
|
||||||
|
@ -83,6 +94,7 @@ class TemplateTest extends TestCase
|
||||||
$b, 'hello, Username!'),
|
$b, 'hello, Username!'),
|
||||||
array('hello, {"World"}!', $a, 'hello, World!'),
|
array('hello, {"World"}!', $a, 'hello, World!'),
|
||||||
array('hello, {"W{$a}d"}!', $a, 'hello, WWorldd!'),
|
array('hello, {"W{$a}d"}!', $a, 'hello, WWorldd!'),
|
||||||
|
array('hello, {$world->chunk(1)->self->chunk("new")}!', $b, 'hello, world!'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user