diff --git a/README.md b/README.md
index 5a77dff..ad30fd1 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
-Aspect - awesome template engine for PHP
+Cytro - awesome template engine for PHP
==========================
-> Composer package: `{"bzick/aspect": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/aspect)
+> Composer package: `{"bzick/cytro": "dev-master"}`. See on [Packagist.org](https://packagist.org/packages/bzick/aspect)
-[![Build Status](https://travis-ci.org/bzick/aspect.png?branch=master)](https://travis-ci.org/bzick/aspect)
+[![Build Status](https://travis-ci.org/bzick/aspect.png?branch=master)](https://travis-ci.org/bzick/cytro)
## [About](./docs/about.md) :: [Documentation](./docs/main.md) :: [Benchmark](./docs/benchmark.md) :: [Articles](./docs/articles.md)
* Simplest known [syntax](./docs/syntax.md)
@@ -20,11 +20,11 @@ Simple template
```smarty
- Aspect
+ Cytro
- {if $templaters.aspect?}
- {var $tpl = $templaters.aspect}
+ {if $templaters.cytro?}
+ {var $tpl = $templaters.cytro}
Name: {$tpl.name}
Description: {$tpl.name|truncate:80}
@@ -41,24 +41,24 @@ Display template
```php
display("pages/about.tpl", $data);
+$cytro = Cytro::factory('./templates', './compiled', Cytro::CHECK_MTIME);
+$cytro->display("pages/about.tpl", $data);
```
Get content
```php
fetch("pages/about.tpl", $data);
+$cytro = Cytro::factory('./templates', './compiled', Cytro::CHECK_MTIME);
+$content = $cytro->fetch("pages/about.tpl", $data);
```
Runtime compilation
```php
compileCode('Hello {$user.name}! {if $user.email?} Your email: {$user.email} {/if}');
+$cytro = new Cytro();
+$tempate = $cytro->compileCode('Hello {$user.name}! {if $user.email?} Your email: {$user.email} {/if}');
$tempate->display($data);
// or
$content = $tempate->fetch($data);
diff --git a/benchmark/aspect/benchmark/compile.aspect.php b/benchmark/aspect/benchmark/compile.aspect.php
deleted file mode 100644
index 43d3213..0000000
--- a/benchmark/aspect/benchmark/compile.aspect.php
+++ /dev/null
@@ -1,22 +0,0 @@
-
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/compile.smarty3.php b/benchmark/aspect/benchmark/compile.smarty3.php
deleted file mode 100644
index 538a5a1..0000000
--- a/benchmark/aspect/benchmark/compile.smarty3.php
+++ /dev/null
@@ -1,23 +0,0 @@
-addTemplateDir(__DIR__.'/../templates');
-$smarty->setCompileDir(__DIR__.'/../compiled');
-
-$t = microtime(1);
-$tpl = $smarty->createTemplate('syntax.tpl');
-/* @var Smarty_Internal_Template $tpl */
-$tpl->compileTemplateSource();
-$t = microtime(1) - $t;
-var_dump("First compile: ".$t);
-
-$t = microtime(1);
-$tpl = $smarty->createTemplate('syntax.tpl');
-/* @var Smarty_Internal_Template $tpl */
-$tpl->compileTemplateSource();
-$t = microtime(1) - $t;
-var_dump("Second compile: ".$t);
-
-var_dump("Pick memory: ".memory_get_peak_usage());
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/data.php b/benchmark/aspect/benchmark/data.php
deleted file mode 100644
index 78cf3a8..0000000
--- a/benchmark/aspect/benchmark/data.php
+++ /dev/null
@@ -1,87 +0,0 @@
- "syntax test page",
-
- "user" => array(
- "email" => 'bzick@megagroup.ru',
- "name" => 'Ivan'
- ),
-
- "data" => array(
- 1 => array(
- "foo" => "data.1.foo value"
- ),
- 2 => 4,
- 4 => "data.four value",
- 5 => array(
- "bar" => "data.5.baz value",
- "baz" => array(
- "foo" => "data.5.baz.foo value"
- )
- ),
- 6 => array(
- "foo" => "data.6.foo value"
- ),
- "bar" => "data.bar value",
- "barz" => "data.barz value",
- "baz_key" => "baz",
- "foo" => array(
- "bar" => "data.foo.baz value",
- "baz" => array(
- "foo" => "data.foo.baz.foo value",
- "ls" => array(
- 4 => "data.foo.baz.ls.4 value",
- 5 => 555
- )
- )
- ),
- "obj" => new obj(),
- "tpl_name" => 'subdir/subtpl'
- ),
-
- "foo_key" => "foo",
- "bar_key" => "bar",
- "barz_key" => "barz",
- "baz_key" => "baz",
-
- "item" => "some item",
- "x" => 1,
- "y" => 2,
- "tpl_name" => "subtpl",
-
- "contacts" => array(
- array(
- "foo" => "bar",
- "foo1" => "bar1",
- "foo2" => "bar2",
- ),
- array(
- "baz" => "buh",
- "baz1" => "buh1",
- "baz2" => "buh2",
- )
- ),
- "logged_in" => false
-);
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/execute.aspect.php b/benchmark/aspect/benchmark/execute.aspect.php
deleted file mode 100644
index 9a8ad52..0000000
--- a/benchmark/aspect/benchmark/execute.aspect.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/execute.native.php b/benchmark/aspect/benchmark/execute.native.php
deleted file mode 100644
index 11d4fe7..0000000
--- a/benchmark/aspect/benchmark/execute.native.php
+++ /dev/null
@@ -1,23 +0,0 @@
-
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/execute.simple.aspect.php b/benchmark/aspect/benchmark/execute.simple.aspect.php
deleted file mode 100644
index 4135b04..0000000
--- a/benchmark/aspect/benchmark/execute.simple.aspect.php
+++ /dev/null
@@ -1,25 +0,0 @@
- "Ivan",
- "email" => "bzick@megagroup.ru"
-);
-
-$data = Aspect::fetch('simple.tpl', $_data, 0);
-
-$dt = microtime(1);
-$data = Aspect::fetch('simple.tpl', $_data, 0);
-$dt = microtime(1) - $dt;
-
-
-echo "\n=====================\nCompile: $ct\nDisplay: $dt\n";
-?>
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/execute.simple.smarty3.php b/benchmark/aspect/benchmark/execute.simple.smarty3.php
deleted file mode 100644
index 8e1803e..0000000
--- a/benchmark/aspect/benchmark/execute.simple.smarty3.php
+++ /dev/null
@@ -1,29 +0,0 @@
-addTemplateDir(__DIR__.'/../templates');
-$smarty->setCompileDir(__DIR__.'/../compiled');
-
-$ct = microtime(1);
-$tpl = $smarty->createTemplate('simple.tpl');
-/* @var Smarty_Internal_Template $tpl */
-$tpl->compileTemplateSource();
-$ct = microtime(1) - $ct;
-
-$_data = array(
- "name" => "Ivan",
- "email" => "bzick@megagroup.ru"
-);
-
-$smarty->assign($_data);
-$data = $smarty->fetch('simple.tpl');
-
-$t = microtime(1);
-$smarty->assign($_data);
-$data = $smarty->fetch('simple.tpl');
-$dt = microtime(1) - $t;
-
-
-echo "\n=====================\nCompile: $ct\nDisplay: $dt\n";
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/execute.smarty3.php b/benchmark/aspect/benchmark/execute.smarty3.php
deleted file mode 100644
index 0adcc35..0000000
--- a/benchmark/aspect/benchmark/execute.smarty3.php
+++ /dev/null
@@ -1,29 +0,0 @@
-addTemplateDir(__DIR__.'/../templates');
-$smarty->setCompileDir(__DIR__.'/../compiled');
-
-/*$ct = microtime(1);
-$tpl = $smarty->createTemplate('syntax.tpl');
-/* @var Smarty_Internal_Template $tpl */
-/*$tpl->compileTemplateSource();
-$ct = microtime(1) - $ct;
-echo "\n=====================\nCompile: $ct\n";
-*/
-
-$_data = require_once __DIR__.'/data.php';
-
-$smarty->assign($_data);
-$data = $smarty->fetch('syntax.tpl');
-
-$t = microtime(1);
-$smarty->assign($_data);
-$data = $smarty->fetch('syntax.tpl');
-$dt = microtime(1) - $t;
-
-$data = MF\Misc\Str::strip($data, true);
-echo "$data\n====\n".md5($data)."\n=====================\nDisplay: $dt\n";
-var_dump("Pick memory: ".memory_get_peak_usage());
\ No newline at end of file
diff --git a/benchmark/aspect/benchmark/foreach.last.php b/benchmark/aspect/benchmark/foreach.last.php
deleted file mode 100644
index f487c98..0000000
--- a/benchmark/aspect/benchmark/foreach.last.php
+++ /dev/null
@@ -1,47 +0,0 @@
- $v) {
- if(!--$c) var_dump("last");
- //var_dump($v);
-}
-
-print_r("\n\nforeach + count: ".(microtime(1) - $t)."\n\n");
-
-$t = microtime(1);
-reset($a);
-while(list($k, $v) = each($a)) {
- if(key($a) === null) {
- var_dump("last");
- }
- /*next($a);
- if(key($a) === null) {
- var_dump("last");
- }*/
- //var_dump($v);
-}
-print_r("\neach: ".(microtime(1) - $t)."\n\n");
-
-$t = microtime(1);
-foreach($a as $k => $v) {
- //var_dump($v);
-}
-
-print_r("\n\nforeach: ".(microtime(1) - $t)."\n\n");
-?>
diff --git a/benchmark/aspect/templates/fullsyntax.tpl b/benchmark/aspect/templates/fullsyntax.tpl
deleted file mode 100644
index 6366e79..0000000
--- a/benchmark/aspect/templates/fullsyntax.tpl
+++ /dev/null
@@ -1,94 +0,0 @@
-{*
- data.value = "TXT value";
- data.arr.dot.4.retval = "Four";
- data.arr.dot.5 = "FiVe";
- data.arr.i = 4;
- data.arr.retval = "Retval key";
- data.set->get = "Get props";
- data.iam->getName(...) == "return Name";
- data.iam->getFormat(...)== "return Format";
- data.num = 777;
- data.k = 0;
- data.ls = array("a" => "lit A", "c" => "lit C", "d" => "lit D");
-
-*}
-Hello world!
-My Name is {$data.value}...
-Yeah
-
-Hello world!
-My Name is {$data.arr.dot|json_encode|lower}...
-Yeah
-
-Hello world, {$data.value|upper}!
-My Name is {$data.arr[dot].5|upper}...
-My Name is {$data.arr.dot[ $data.arr.i|round ]."retval"|upper}...
-My Name is {$data.arr."retval"|upper}...
-Yeah
-
-Hello world!
-My Name is {$data.set->get|upper}...
-Yeah
-
-Hello world!
-My Name is {$data.iam->getName()|upper}...
-Your Name is {$data.you->getFormat(1, 0.4, "%dth", 'grade', $data.arr[dot].5|lower)|upper}?
-Yeah
-
-
-Hello world!
-{if isset($data.iam) && !empty($data.set->get)}
-My Name is {$data.set->get}...
-{/if}
-Yeah
-
-Hello world!
-{if $data.num >= 5 && $data.k++ || foo($data.value) && !bar($data.num) + 3 || $data.k?}
-My Name is {$data->user|upper}...
-{/if}
-Yeah
-
-Hello world!
-{foreach from=$data.ls key=k item=e}
-My Name is {$e|upper} ({$k})...
-{/foreach}
-Yeah
-
-Hello world!
-{switch $data.num}
- {case "dotted"}
-dotted lines
- {break}
- {case 777}
-numeric lines
- {break}
- {case $data[arr]["dot"].4.retval|upper}
-lister
- {break}
-{/switch}
-Yeah
-
-Hello world!
-{* if !empty($data.num) *}
-{if $data.num?}
- dotted lines
-{elseif $data[arr]["dot"].4.retval|lower}
- lister
-{/if}
-Yeah
-
-Check system variable
-Current timestamp {$aspect.now}...
-$_GET {$aspect.get.item}...
-$_POST {$aspect.post.myval|upper}...
-$_COOKIES {$aspect.cookies["uid"]}...
-$_REQUEST {$aspect.request?}...
-Consts {$data.number|round:$aspect.const.PHP_INT_MAX}...
-Ok
-
-
-Hello world!
-{for from=1 to=$data.ls|count}
-Go
-{/for}
-Yeah
\ No newline at end of file
diff --git a/benchmark/aspect/templates/simple.tpl b/benchmark/aspect/templates/simple.tpl
deleted file mode 100644
index 08e1283..0000000
--- a/benchmark/aspect/templates/simple.tpl
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- Simple template about {$name|upper}
-
-
-
-{if $name}
- My name is {$name}
-{else}
- I haven't name :(
-{/if}
-
-Ok.
-
-My email {$email}. It is great!
-
-
\ No newline at end of file
diff --git a/benchmark/aspect/templates/subdir/subtpl.php b/benchmark/aspect/templates/subdir/subtpl.php
deleted file mode 100644
index cc10f25..0000000
--- a/benchmark/aspect/templates/subdir/subtpl.php
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-Ok.
-
-My email
-
-
\ No newline at end of file
diff --git a/benchmark/aspect/templates/subdir/subtpl.tpl b/benchmark/aspect/templates/subdir/subtpl.tpl
deleted file mode 100644
index f152c35..0000000
--- a/benchmark/aspect/templates/subdir/subtpl.tpl
+++ /dev/null
@@ -1,9 +0,0 @@
-{if $user.name}
- My name is {$user.name}
-{else}
- I haven't name :(
-{/if}
-
-Ok.
-
-My email {$user.name}. It is great!
\ No newline at end of file
diff --git a/benchmark/aspect/templates/syntax.php b/benchmark/aspect/templates/syntax.php
deleted file mode 100644
index 35a3f5e..0000000
--- a/benchmark/aspect/templates/syntax.php
+++ /dev/null
@@ -1,184 +0,0 @@
-
-
-
-
-
-
-
-Simple manipulations
-
-
-
-
-
-
-
-
-value; ?>
-method(); ?>
-
-Many other combinations are allowed
-
-
-
-
-
-
-
-
-methodArgs($tpl["baz_key"], 2, 2.3, "some string", $tpl["bar_key"]); ?> <-- passing parameters
-
-
-Math and embedding tags:
-
- // will output the sum of x and y.
-
- // tags within tags
-
- // tags within double quoted strings
-
-
-Short variable assignment:
-
-
- // function in assignment
- // as function parameter
- // assign to specific array element
-
-
-Smarty "dot" syntax (note: embedded {} are used to address ambiguities):
-
-
-
-
-
-
-Object chaining:
-
-getSelf($tpl["x"])->method($tpl["y"]); ?>
-
-Direct PHP function access:
-
-
-
-
-'.$tpl["name"].'';
- } else {
- echo "hi, ".$tpl["user"]["name"];
- }
-?>
-
-Embedding Vars in Double Quotes
-
- $tpl["user"]["email"],"text" => "test ".$tpl["item"]." test"), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".$tpl["foo_key"]." test"), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".($tpl["data"][4])." test"), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".$tpl["item"].".bar test"), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => 'test {$data.barz} test'), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".($tpl["data"]["barz"])." test"), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => strtoupper("test ".($tpl["data"]["barz"])." test")), $tpl).
- MF\Aspect\Func::mailto(array("address" => $tpl["user"]["email"],"text" => "test ".(strtoupper($tpl["data"]["barz"]))." test"), $tpl); ?>
-
-
-will replace $tpl_name with value
-
-
-does NOT replace $tpl_name
- $tpl["user"]["email"],"text" => "one,two"), $tpl); ?>
-
-
-
-Math
-
-some more complicated examples
-
-num * !$tpl["data"]["foo"]["baz"]["ls"][4] - 3 * 7 % $tpl["data"][2]; ?>
-
-num * $tpl["data"]["foo"]["baz"]["ls"][4] - 3 * 7 % $tpl["data"][2]) {
- echo MF\Misc\Str::truncate($tpl["data"]["barz"], "".($tpl["data"][2] / 2 - 1)."")."\n".
- MF\Misc\Str::truncate($tpl["data"]["barz"], ($tpl["data"][2] / 2 - 1));
- }
-?>
-
-Escaping Smarty Parsing
-
-
-
-
-name:
-email:
-
-Modifier examples
-
-apply modifier to a variable
-
-
-modifier with parameters
-
-
-apply modifier to a function parameter
- $tpl["user"]["email"],"text" => strtoupper($tpl["user"]["name"])), $tpl); ?>
-
-with parameters
- $tpl["user"]["email"],"text" => MF\Misc\Str::truncate($tpl["user"]["name"], 40, "...")), $tpl); ?>
-
-apply modifier to literal string
-
-using date_format to format the current date
-
-
-apply modifier to a custom function
-
-Foreach
- $tpl["value"]) {
- echo $tpl["key"].": ".$tpl["value"]." ";
- }
- } else {
- echo "no items";
- }
- }
- }
-?>
-
-If condition
-
-
-
- 0) {
- echo "do a foreach loop";
- }
-?>
-
-
-
-
-
\ No newline at end of file
diff --git a/benchmark/aspect/templates/syntax.tpl b/benchmark/aspect/templates/syntax.tpl
deleted file mode 100644
index da23378..0000000
--- a/benchmark/aspect/templates/syntax.tpl
+++ /dev/null
@@ -1,179 +0,0 @@
-
-
- {$title}
-
-
-
-{* this is a comment *}
-
-Simple manipulations
-
-{$item}
-{$data[4]}
-{$data.bar}
-{*$data[bar]*}
-{$data["bar"]}
-{$data['bar']}
-{$data.$bar_key}
-{$data.obj->value}
-{$data.obj->method()}
-
-Many other combinations are allowed
-
-{$data.foo.bar}
-{$data.foo.$baz_key.$foo_key}
-{$data.foo.$bar_key}
-{$data.$foo_key.bar}
-{$data[5].bar}
-{$data[5].$bar_key}
-{$data.foo.$baz_key.ls[4]}
-{$data.obj->methodArgs($baz_key, 2, 2.3, "some string", $bar_key)} <-- passing parameters
-{*"foo"*}
-
-
-Math and embedding tags:
-
-{$x+$y} // will output the sum of x and y.
-{$data[$x+3]}
-{$item=4+3} // tags within tags
-{$data[4]=4+3}
-{$item="this is message"} // tags within double quoted strings
-
-
-Short variable assignment:
-
-{$item=$y+2}
-{$item = strlen($bar_key)} // function in assignment
-{$item = intval( ($x+$y)*3 )} // as function parameter
-{$data.bar=1} // assign to specific array element
-{$data.foo.bar="data.foo.bar: tpl value"}
-
-Smarty "dot" syntax (note: embedded {} are used to address ambiguities):
-
-{$data.foo.baz.foo}
-{$data.foo.$baz_key.foo}
-{$data[$y+4].foo}
-{$data.foo[$data.baz_key].foo}
-
-Object chaining:
-
-{$data.obj->getSelf($x)->method($y)}
-
-Direct PHP function access:
-
-{strlen("hi!")}
-
-
-{if $logged_in}
-Welcome, {$name}!
-{else}
-hi, {$user.name}
-{/if}
-
-Embedding Vars in Double Quotes
-
-{mailto address=$user.email text="test $item test"}
-{mailto address=$user.email text="test $foo_key test"}
-{mailto address=$user.email text="test {$data[4]} test"}
-{*mailto address=$user.email text="test {$data[barz]} test"*}
-{mailto address=$user.email text="test $item.bar test"}
-{mailto address=$user.email text='test {$data.barz} test'}
-{mailto address=$user.email text="test {$data.barz} test"}
-{mailto address=$user.email text="test {$data.barz} test"|upper}
-{mailto address=$user.email text="test {$data.barz|upper} test"}
-
-
-will replace $tpl_name with value
-{include file="subdir/$tpl_name.tpl"}
-
-does NOT replace $tpl_name
-{mailto address=$user.email text="one,two"}
-
-{include file="{$data.tpl_name}.tpl"}
-
-Math
-
-some more complicated examples
-
-{$data[2] - $data.obj->num * !$data.foo.baz.ls[4] - 3 * 7 % $data[2]}
-
-{if $data[2] - $data.obj->num * $data.foo.baz.ls[4] - 3 * 7 % $data[2]}
- {$data.barz|truncate:"{$data[2]/2-1}"}
- {$data.barz|truncate:($data[2]/2-1)}
-{/if}
-
-Escaping Smarty Parsing
-
-
-
-
-name: {$user.name}
-email: {$user.email}
-
-Modifier examples
-
-apply modifier to a variable
-{$user.name|upper}
-
-modifier with parameters
-{$user.name|truncate:40:"..."}
-
-apply modifier to a function parameter
-{mailto address=$user.email text=$user.name|upper}
-
-with parameters
-{mailto address=$user.email text=$user.name|truncate:40:"..."}
-
-apply modifier to literal string
-{*"foobar"|upper*}
-
-using date_format to format the current date
-{$smarty.now|date_format:"%Y/%m/%d"}
-
-apply modifier to a custom function
-{*mailto|upper address="smarty@example.com"*}
-
-Foreach
-{foreach $contacts as $contact}
- {foreach $contact as $key => $value}
- {$key}: {$value}
- {foreachelse}
- no items
- {/foreach}
-{/foreach}
-
-If condition
-{if isset($user.name) && $user.name == 'yandex'}
-do something
-{elseif $user.name == $data.foo.bar}
-do something2
-{/if}
-
-{*switch $item}
- {case 1}
- item 1
- {break}
- {case 2}
- item 2
- {break}
- {default}
- on item
-{/switch*}
-
-{if is_array($data.foo) && count($data.foo) > 0}
-do a foreach loop
-{/if}
-
-
-
-
\ No newline at end of file
diff --git a/benchmark/aspect/test.php b/benchmark/aspect/test.php
deleted file mode 100644
index bfe2fe1..0000000
--- a/benchmark/aspect/test.php
+++ /dev/null
@@ -1,103 +0,0 @@
-world!
-My Name is {$data.value}...
-Yeah';
-
-$tpl[1] = 'Hello world!
-My Name is {$data.value[label].dot|json_decode|lower|truncate:80:"...":true:null:0.22:$a.keyz|upper}...
-Yeah';
-
-$tpl[2] = 'Hello world, {$user.name|upper}!
-My Name is {$data.user1.5.$i."return"[ $hello.world|lower ]|upper}...
-Yeah';
-
-$tpl[3] = 'Hello world!
-My Name is {$data->set->get|upper}...
-Yeah';
-
-$tpl[4] = 'Hello world!
-My Name is {$iam->getName()|upper}...
-Your Name is {$you->getFromat(1, 0.4, "%dth", \'grade\', $global->name.k|lower)|upper}?
-Yeah';
-
-$tpl[5] = 'Hello world!
-{if isset($data.user) && !empty($data->value)}
-My Name is {$data->user|upper}...
-{/if}
-Yeah';
-
-$tpl[6] = 'Hello world!
-{if $data.user >= 5 && $k++ || foo($data->value) && !bar($d) + 3 || $show.go?}
-My Name is {$data->user|upper}...
-{/if}
-Yeah';
-
-$tpl[7] = 'Hello world!
-{foreach from=$users."list" key=k item=e}
-My Name is {$e|upper} ({$k})...
-{/foreach}
-Yeah';
-
-$tpl[8] = 'Hello world!
-{switch $data->enum}
- {case "dotted"}
- dotted lines
- {break}
- {case 7}
- numeric lines
- {break}
- {case $list|truncate}
- lister
- {break}
-{/switch}
-Yeah';
-
-$tpl[9] = 'Hello world!
-{if $data->enum?}
- dotted lines
-{elseif $list|truncate}
- lister
-{/if}
-Yeah';
-
-$tpl[10] = 'Check system variable
-Current timestamp {$aspect.now}...
-$_GET {$aspect.get.item}...
-$_POST {$aspect.post.myval|upper}...
-$_COOKIES {$aspect.cookies["uid"]}...
-$_REQUEST {$aspect.request?}...
-Consts {$number|round:$aspect.const.PHP_INT_MAX|}...
-Ok';
-
-$tpl[11] = 'Hello world!
-{for from=1 to=$e|count}
-Go
-{/for}
-Yeah';
-
-$tpl_ = '
-Hello world!
-My Name is {$data|upper}...
- {* comment *}
-I have
-
-{foreach $items as $key => $item}
- - {$item}
-{/foreach}
-
-';
-
-$template = new MF\Aspect\Template($tpl[7], 'my.tpl');
-//var_dump(Tokenizer::decode('case 6:'));
-//exit;
-echo "\n".$template->getBody()."\n";
-//var_dump($template->fetch(array("data" => array("value" => "Yohoho"))));
-?>
\ No newline at end of file
diff --git a/benchmark/run.php b/benchmark/run.php
index f28ac5b..e5802eb 100644
--- a/benchmark/run.php
+++ b/benchmark/run.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/scripts/bootstrap.php';
exec("rm -rf ".__DIR__."/compile/*");
-echo "Smarty3 vs Twig vs Aspect\n\n";
+echo "Smarty3 vs Twig vs Cytro\n\n";
echo "Generate templates... ";
passthru("php ".__DIR__."/templates/inheritance/smarty.gen.php");
@@ -32,6 +32,6 @@ echo "\nDone. Cleanup.\n";
passthru("rm -f ".__DIR__."/templates/inheritance/smarty/*");
passthru("rm -f ".__DIR__."/templates/inheritance/twig/*");
-echo "\nSmarty3 vs Aspect (more details)\n\n";
+echo "\nSmarty3 vs Cytro (more details)\n\n";
echo "Coming soon\n";
\ No newline at end of file
diff --git a/benchmark/scripts/bootstrap.php b/benchmark/scripts/bootstrap.php
index b366236..6741b42 100644
--- a/benchmark/scripts/bootstrap.php
+++ b/benchmark/scripts/bootstrap.php
@@ -45,13 +45,13 @@ class Benchmark {
public static function aspect($tpl, $data, $double, $message) {
- $aspect = Aspect::factory(__DIR__.'/../templates', __DIR__."/../compile/");
+ $cytro = Cytro::factory(__DIR__.'/../templates', __DIR__."/../compile/");
if($double) {
- $aspect->fetch($tpl, $data);
+ $cytro->fetch($tpl, $data);
}
$_SERVER["t"] = $start = microtime(true);
- $aspect->fetch($tpl, $data);
+ $cytro->fetch($tpl, $data);
printf(self::$t, __FUNCTION__, $message, round(microtime(true)-$start, 4), round(memory_get_peak_usage()/1024/1024, 2));
}
diff --git a/benchmark/templates/echo.php b/benchmark/templates/echo.php
index 398d6a8..c59b103 100644
--- a/benchmark/templates/echo.php
+++ b/benchmark/templates/echo.php
@@ -53,13 +53,13 @@ $template = $twig->loadTemplate('echo/twig.tpl');
$template->render($data);
var_dump("Twig cached: ".(microtime(true)-$start));
-$aspect = Aspect::factory(__DIR__, __DIR__."/../compile/", Aspect::AUTO_RELOAD);
+$cytro = Cytro::factory(__DIR__, __DIR__."/../compile/", Cytro::AUTO_RELOAD);
$start = microtime(true);
-$template = $aspect->fetch('echo/smarty.tpl', $data);
-var_dump("Aspect: ".(microtime(true)-$start));
+$template = $cytro->fetch('echo/smarty.tpl', $data);
+var_dump("Cytro: ".(microtime(true)-$start));
$start = microtime(true);
-$template = $aspect->fetch('echo/smarty.tpl', $data);
-var_dump("Aspect cached: ".(microtime(true)-$start));
+$template = $cytro->fetch('echo/smarty.tpl', $data);
+var_dump("Cytro cached: ".(microtime(true)-$start));
diff --git a/benchmark/templates/foreach.php b/benchmark/templates/foreach.php
index 8b1bf3f..1df7c6b 100644
--- a/benchmark/templates/foreach.php
+++ b/benchmark/templates/foreach.php
@@ -38,13 +38,13 @@ $template = $twig->loadTemplate('foreach/twig.tpl');
$template->render($data);
var_dump("Twig cached: ".(microtime(true)-$start));
-$aspect = Aspect::factory(__DIR__, __DIR__."/../compile/", Aspect::AUTO_RELOAD | Aspect::INCLUDE_SOURCES);
+$cytro = Cytro::factory(__DIR__, __DIR__."/../compile/", Cytro::AUTO_RELOAD);
$start = microtime(true);
-$template = $aspect->fetch('foreach/smarty.tpl', $data);
-var_dump("Aspect: ".(microtime(true)-$start));
+$template = $cytro->fetch('foreach/smarty.tpl', $data);
+var_dump("Cytro: ".(microtime(true)-$start));
$start = microtime(true);
-$template = $aspect->fetch('foreach/smarty.tpl', $data);
-var_dump("Aspect cached: ".(microtime(true)-$start));
+$template = $cytro->fetch('foreach/smarty.tpl', $data);
+var_dump("Cytro cached: ".(microtime(true)-$start));
diff --git a/benchmark/templates/inheritance.php b/benchmark/templates/inheritance.php
index 0872640..7b170f9 100644
--- a/benchmark/templates/inheritance.php
+++ b/benchmark/templates/inheritance.php
@@ -49,13 +49,13 @@ $template = $twig->loadTemplate('inheritance/twig/b100.tpl');
$template->render($data);
var_dump("Twig cached: ".(microtime(true)-$start));
-$aspect = Aspect::factory(__DIR__, __DIR__."/../compile/", Aspect::AUTO_RELOAD);
+$cytro = Cytro::factory(__DIR__, __DIR__."/../compile/", Cytro::AUTO_RELOAD);
$start = microtime(true);
-$template = $aspect->fetch('inheritance/smarty/b100.tpl', $data);
-var_dump("Aspect: ".(microtime(true)-$start));
+$template = $cytro->fetch('inheritance/smarty/b100.tpl', $data);
+var_dump("Cytro: ".(microtime(true)-$start));
$start = microtime(true);
-$template = $aspect->fetch('inheritance/smarty/b100.tpl', $data);
-var_dump("Aspect cached: ".(microtime(true)-$start));
+$template = $cytro->fetch('inheritance/smarty/b100.tpl', $data);
+var_dump("Cytro cached: ".(microtime(true)-$start));
diff --git a/composer.json b/composer.json
index 83b4bf7..8c04980 100644
--- a/composer.json
+++ b/composer.json
@@ -1,9 +1,9 @@
{
- "name": "bzick/aspect",
+ "name": "bzick/cytro",
"type": "library",
- "description": "Aspect - fast template engine for PHP",
- "homepage": "https://github.com/bzick/aspect",
- "keywords": ["aspect", "template", "templating"],
+ "description": "Cytro - fast template engine for PHP",
+ "homepage": "http://cytro.org/",
+ "keywords": ["cytro", "template", "templating"],
"license": "MIT",
"authors": [
{
@@ -21,7 +21,7 @@
"twig/twig": "1.*"
},
"autoload": {
- "psr-0": { "Aspect\\": "src/" },
- "classmap": [ "src/Aspect.php" ]
+ "psr-0": { "Cytro\\": "src/" },
+ "classmap": [ "src/Cytro.php" ]
}
}
diff --git a/docs/about.md b/docs/about.md
index a746e26..579891f 100644
--- a/docs/about.md
+++ b/docs/about.md
@@ -1,7 +1,7 @@
-About Aspect [RU]
-=================
+About Cytro [RU]
+================
-Aspect - самый быстрый, гибкий и тонкий шаблонизатор для PHP, унаследовавший синтаксис от Smarty3 и улучшив его.
+Cytro - самый быстрый, гибкий и тонкий шаблонизатор для PHP, унаследовавший синтаксис от Smarty3 и улучшив его.
Пожалуй это единственный шаблонизатор, который не использет ни регулярные выражения, как Twig, ни лексер от BISON, как Smarty3.
Вы не найдёте ни одного регулярного выражения в ядре Aspect, но тем не менее ядро простое, компактное и очень быстрое.
diff --git a/docs/benchmark.md b/docs/benchmark.md
index d04e93b..3d84090 100644
--- a/docs/benchmark.md
+++ b/docs/benchmark.md
@@ -15,9 +15,9 @@ To start benchmark run script `benchmark/run.php`.
twig: compiled and !loaded 0.0337 sec, 16.1 MiB
twig: compiled and loaded 0.0027 sec, 16.1 MiB
- aspect: !compiled and !loaded 1.0142 sec, 8.8 MiB
- aspect: compiled and !loaded 0.0167 sec, 6.1 MiB
- aspect: compiled and loaded 0.0024 sec, 6.1 MiB
+ cytro: !compiled and !loaded 1.0142 sec, 8.8 MiB
+ cytro: compiled and !loaded 0.0167 sec, 6.1 MiB
+ cytro: compiled and loaded 0.0024 sec, 6.1 MiB
Iterates array
@@ -29,9 +29,9 @@ To start benchmark run script `benchmark/run.php`.
twig: compiled and !loaded 0.0605 sec, 2.9 MiB
twig: compiled and loaded 0.0550 sec, 2.9 MiB
- aspect: !compiled and !loaded 0.0093 sec, 3.0 MiB
- aspect: compiled and !loaded 0.0033 sec, 2.4 MiB
- aspect: compiled and loaded 0.0027 sec, 2.4 MiB
+ cytro: !compiled and !loaded 0.0093 sec, 3.0 MiB
+ cytro: compiled and !loaded 0.0033 sec, 2.4 MiB
+ cytro: compiled and loaded 0.0027 sec, 2.4 MiB
templates inheritance
@@ -43,9 +43,9 @@ To start benchmark run script `benchmark/run.php`.
twig: compiled and !loaded 0.0255 sec, 6.3 MiB
twig: compiled and loaded 0.0038 sec, 6.3 MiB
- aspect: !compiled and !loaded 0.1222 sec, 3.9 MiB
- aspect: compiled and !loaded 0.0004 sec, 2.4 MiB
- aspect: compiled and loaded 0.0000 sec, 2.4 MiB
+ cytro: !compiled and !loaded 0.1222 sec, 3.9 MiB
+ cytro: compiled and !loaded 0.0004 sec, 2.4 MiB
+ cytro: compiled and loaded 0.0000 sec, 2.4 MiB
* **!compiled and !loaded** - template engine object created but parsers not initialized and templates not compiled
* **compiled and !loaded** - template engine object created, template compiled but not loaded
diff --git a/docs/install.md b/docs/install.md
index de30690..4cfc6e6 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -5,11 +5,11 @@ For installation use [composer](http://getcompoer.org). Add in your `composer.js
```json
{
"require": {
- "bzick/aspect": "dev-master"
+ "bzick/cytro": "dev-master"
}
}
```
or use shell
-`composer require bzick/aspect`
+`composer require bzick/cytro`
-If you do not use composer - use `psr-0` format for loading Aspect's classes.
+If you do not use composer - use `psr-0` format for loading Cytro's classes.
diff --git a/docs/main.md b/docs/main.md
index 922ed2c..0efc641 100644
--- a/docs/main.md
+++ b/docs/main.md
@@ -1,7 +1,7 @@
Documentation
=============
-### Aspect
+### Cytro
* [About](./about.md)
* [Install](./install.md)
diff --git a/docs/mods/length.md b/docs/mods/length.md
index 62e8408..c91ab54 100644
--- a/docs/mods/length.md
+++ b/docs/mods/length.md
@@ -5,4 +5,5 @@ Modifier length [RU]
* если массив - длина массива
* если итератор - длина итератора
-* если строка - длина строки (поддерживается UTF8 и не требует `mbstring`)
\ No newline at end of file
+* если строка - длина строки (поддерживается UTF8 и не требует `mbstring`)
+* для других значений возвращается 0
\ No newline at end of file
diff --git a/docs/settings.md b/docs/settings.md
index 9a8cd6b..de85cff 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -6,31 +6,31 @@ Settings [RU]
Что бы установить папку для хранения кеша собранных шаблонов
```php
-$aspect->setCompileDir($dir);
+$cytro->setCompileDir($dir);
```
### Template settings
```php
// set options using factory
-$aspect = Aspect::factory($tpl_dir, $compile_dir, $options);
+$cytro = Cytro::factory($tpl_dir, $compile_dir, $options);
// or inline using method setOptions
-$aspect->setOptions($options);
+$cytro->setOptions($options);
```
Параметры могут быть массивом `'option_name' => true` (если ключ не указан автоматически задаётся false) или битовой маской.
-* **disable_methods**, `Aspect::DENY_METHODS`, запретить вызов методов у объектов
-* **disable_native_funcs**, `Aspect::DENY_INLINE_FUNCS`, запретить использование PHP функций, кроме разрешенных
-* **auto_reload**, `Aspect::AUTO_RELOAD`, пересобирать шаблон если его оригинал был изменён (замедляет работу шаблонизатора).
-* **force_compile**, `Aspect::FORCE_COMPILE`, пересобирать шаблон при каждом вызове (сильно замедляет работу шаблонизатора).
-* **force_include**, `Aspect::FORCE_INCLUDE`, оптимизировать вставку шаблона в шаблон. Это увеличит производительность и размер собранного шаблона.
+* **disable_methods**, `Cytro::DENY_METHODS`, запретить вызов методов у объектов
+* **disable_native_funcs**, `Cytro::DENY_INLINE_FUNCS`, запретить использование PHP функций, кроме разрешенных
+* **auto_reload**, `Cytro::AUTO_RELOAD`, пересобирать шаблон если его оригинал был изменён (замедляет работу шаблонизатора).
+* **force_compile**, `Cytro::FORCE_COMPILE`, пересобирать шаблон при каждом вызове (сильно замедляет работу шаблонизатора).
+* **force_include**, `Cytro::FORCE_INCLUDE`, оптимизировать вставку шаблона в шаблон. Это увеличит производительность и размер собранного шаблона.
```php
-$aspect->setOptions(array(
+$cytro->setOptions(array(
"compile_check" => true,
"force_include" => true
));
// same
-$aspect->setOptions(Aspect::AUTO_RELOAD | Aspect::FORCE_INCLUDE);
+$cytro->setOptions(Cytro::AUTO_RELOAD | Cytro::FORCE_INCLUDE);
```
\ No newline at end of file
diff --git a/src/Aspect.php b/src/Cytro.php
similarity index 79%
rename from src/Aspect.php
rename to src/Cytro.php
index 9396626..7960c93 100644
--- a/src/Aspect.php
+++ b/src/Cytro.php
@@ -1,11 +1,11 @@
'strtoupper',
"lower" => 'strtolower',
"low" => 'strtolower',
- "date_format" => 'Aspect\Modifier::dateFormat',
- "date" => 'Aspect\Modifier::date',
- "truncate" => 'Aspect\Modifier::truncate',
- "escape" => 'Aspect\Modifier::escape',
- "e" => 'Aspect\Modifier::escape', // alias of escape
- "unescape" => 'Aspect\Modifier::unescape',
- "strip" => 'Aspect\Modifier::strip',
- "default" => 'Aspect\Modifier::defaultValue'
+ "date_format" => 'Cytro\Modifier::dateFormat',
+ "date" => 'Cytro\Modifier::date',
+ "truncate" => 'Cytro\Modifier::truncate',
+ "escape" => 'Cytro\Modifier::escape',
+ "e" => 'Cytro\Modifier::escape', // alias of escape
+ "unescape" => 'Cytro\Modifier::unescape',
+ "strip" => 'Cytro\Modifier::strip',
+ "default" => 'Cytro\Modifier::defaultValue'
);
/**
@@ -101,116 +101,116 @@ class Aspect {
protected $_actions = array(
'foreach' => array( // {foreach ...} {break} {continue} {foreachelse} {/foreach}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::foreachOpen',
- 'close' => 'Aspect\Compiler::foreachClose',
+ 'open' => 'Cytro\Compiler::foreachOpen',
+ 'close' => 'Cytro\Compiler::foreachClose',
'tags' => array(
- 'foreachelse' => 'Aspect\Compiler::foreachElse',
- 'break' => 'Aspect\Compiler::tagBreak',
- 'continue' => 'Aspect\Compiler::tagContinue',
+ 'foreachelse' => 'Cytro\Compiler::foreachElse',
+ 'break' => 'Cytro\Compiler::tagBreak',
+ 'continue' => 'Cytro\Compiler::tagContinue',
),
'float_tags' => array('break' => 1, 'continue' => 1)
),
'if' => array( // {if ...} {elseif ...} {else} {/if}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::ifOpen',
- 'close' => 'Aspect\Compiler::stdClose',
+ 'open' => 'Cytro\Compiler::ifOpen',
+ 'close' => 'Cytro\Compiler::stdClose',
'tags' => array(
- 'elseif' => 'Aspect\Compiler::tagElseIf',
- 'else' => 'Aspect\Compiler::tagElse',
+ 'elseif' => 'Cytro\Compiler::tagElseIf',
+ 'else' => 'Cytro\Compiler::tagElse',
)
),
'switch' => array( // {switch ...} {case ...} {break} {default} {/switch}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::switchOpen',
- 'close' => 'Aspect\Compiler::stdClose',
+ 'open' => 'Cytro\Compiler::switchOpen',
+ 'close' => 'Cytro\Compiler::stdClose',
'tags' => array(
- 'case' => 'Aspect\Compiler::tagCase',
- 'default' => 'Aspect\Compiler::tagDefault',
- 'break' => 'Aspect\Compiler::tagBreak',
+ 'case' => 'Cytro\Compiler::tagCase',
+ 'default' => 'Cytro\Compiler::tagDefault',
+ 'break' => 'Cytro\Compiler::tagBreak',
),
'float_tags' => array('break' => 1)
),
'for' => array( // {for ...} {break} {continue} {/for}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::forOpen',
- 'close' => 'Aspect\Compiler::forClose',
+ 'open' => 'Cytro\Compiler::forOpen',
+ 'close' => 'Cytro\Compiler::forClose',
'tags' => array(
- 'forelse' => 'Aspect\Compiler::forElse',
- 'break' => 'Aspect\Compiler::tagBreak',
- 'continue' => 'Aspect\Compiler::tagContinue',
+ 'forelse' => 'Cytro\Compiler::forElse',
+ 'break' => 'Cytro\Compiler::tagBreak',
+ 'continue' => 'Cytro\Compiler::tagContinue',
),
'float_tags' => array('break' => 1, 'continue' => 1)
),
'while' => array( // {while ...} {break} {continue} {/while}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::whileOpen',
- 'close' => 'Aspect\Compiler::stdClose',
+ 'open' => 'Cytro\Compiler::whileOpen',
+ 'close' => 'Cytro\Compiler::stdClose',
'tags' => array(
- 'break' => 'Aspect\Compiler::tagBreak',
- 'continue' => 'Aspect\Compiler::tagContinue',
+ 'break' => 'Cytro\Compiler::tagBreak',
+ 'continue' => 'Cytro\Compiler::tagContinue',
),
'float_tags' => array('break' => 1, 'continue' => 1)
),
'include' => array( // {include ...}
'type' => self::INLINE_COMPILER,
- 'parser' => 'Aspect\Compiler::tagInclude'
+ 'parser' => 'Cytro\Compiler::tagInclude'
),
'var' => array( // {var ...}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::varOpen',
- 'close' => 'Aspect\Compiler::varClose'
+ 'open' => 'Cytro\Compiler::varOpen',
+ 'close' => 'Cytro\Compiler::varClose'
),
'block' => array( // {block ...} {parent} {/block}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::tagBlockOpen',
- 'close' => 'Aspect\Compiler::tagBlockClose',
+ 'open' => 'Cytro\Compiler::tagBlockOpen',
+ 'close' => 'Cytro\Compiler::tagBlockClose',
'tags' => array(
- 'parent' => 'Aspect\Compiler::tagParent'
+ 'parent' => 'Cytro\Compiler::tagParent'
),
'float_tags' => array('parent' => 1)
),
'extends' => array( // {extends ...}
'type' => self::INLINE_COMPILER,
- 'parser' => 'Aspect\Compiler::tagExtends'
+ 'parser' => 'Cytro\Compiler::tagExtends'
),
'use' => array( // {use}
'type' => self::INLINE_COMPILER,
- 'parser' => 'Aspect\Compiler::tagUse'
+ 'parser' => 'Cytro\Compiler::tagUse'
),
'capture' => array( // {capture ...} {/capture}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::captureOpen',
- 'close' => 'Aspect\Compiler::captureClose'
+ 'open' => 'Cytro\Compiler::captureOpen',
+ 'close' => 'Cytro\Compiler::captureClose'
),
'filter' => array( // {filter} ... {/filter}
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::filterOpen',
- 'close' => 'Aspect\Compiler::filterClose'
+ 'open' => 'Cytro\Compiler::filterOpen',
+ 'close' => 'Cytro\Compiler::filterClose'
),
'macro' => array(
'type' => self::BLOCK_COMPILER,
- 'open' => 'Aspect\Compiler::macroOpen',
- 'close' => 'Aspect\Compiler::macroClose'
+ 'open' => 'Cytro\Compiler::macroOpen',
+ 'close' => 'Cytro\Compiler::macroClose'
),
'import' => array(
'type' => self::INLINE_COMPILER,
- 'parser' => 'Aspect\Compiler::tagImport'
+ 'parser' => 'Cytro\Compiler::tagImport'
)
);
/**
* Just factory
*
- * @param string|Aspect\ProviderInterface $source path to templates or custom provider
+ * @param string|Cytro\ProviderInterface $source path to templates or custom provider
* @param string $compile_dir path to compiled files
* @param int $options
* @throws InvalidArgumentException
- * @return Aspect
+ * @return Cytro
*/
public static function factory($source, $compile_dir = '/tmp', $options = 0) {
if(is_string($source)) {
- $provider = new \Aspect\FSProvider($source);
- } elseif($source instanceof Aspect\ProviderInterface) {
+ $provider = new Cytro\FSProvider($source);
+ } elseif($source instanceof ProviderInterface) {
$provider = $source;
} else {
throw new InvalidArgumentException("Source must be a valid path or provider object");
@@ -224,16 +224,16 @@ class Aspect {
}
/**
- * @param Aspect\ProviderInterface $provider
+ * @param Cytro\ProviderInterface $provider
*/
- public function __construct(Aspect\ProviderInterface $provider) {
+ public function __construct(Cytro\ProviderInterface $provider) {
$this->_provider = $provider;
}
/**
* Set compile directory
* @param string $dir directory to store compiled templates in
- * @return Aspect
+ * @return Cytro
*/
public function setCompileDir($dir) {
$this->_compile_dir = $dir;
@@ -268,7 +268,7 @@ class Aspect {
*
* @param string $modifier
* @param string $callback
- * @return Aspect
+ * @return Cytro
*/
public function addModifier($modifier, $callback) {
$this->_modifiers[$modifier] = $callback;
@@ -280,7 +280,7 @@ class Aspect {
*
* @param string $compiler
* @param callable $parser
- * @return Aspect
+ * @return Cytro
*/
public function addCompiler($compiler, $parser) {
$this->_actions[$compiler] = array(
@@ -312,7 +312,7 @@ class Aspect {
* @param callable $open_parser
* @param callable|string $close_parser
* @param array $tags
- * @return Aspect
+ * @return Cytro
*/
public function addBlockCompiler($compiler, $open_parser, $close_parser = self::DEFAULT_CLOSE_COMPILER, array $tags = array()) {
$this->_actions[$compiler] = array(
@@ -330,7 +330,7 @@ class Aspect {
* @param array $tags
* @param array $floats
* @throws LogicException
- * @return Aspect
+ * @return Cytro
*/
public function addBlockCompilerSmart($compiler, $storage, array $tags, array $floats = array()) {
$c = array(
@@ -366,7 +366,7 @@ class Aspect {
* @param string $function
* @param callable $callback
* @param callable|string $parser
- * @return Aspect
+ * @return Cytro
*/
public function addFunction($function, $callback, $parser = self::DEFAULT_FUNC_PARSER) {
$this->_actions[$function] = array(
@@ -380,7 +380,7 @@ class Aspect {
/**
* @param string $function
* @param callable $callback
- * @return Aspect
+ * @return Cytro
*/
public function addFunctionSmart($function, $callback) {
$this->_actions[$function] = array(
@@ -396,7 +396,7 @@ class Aspect {
* @param callable $callback
* @param callable|string $parser_open
* @param callable|string $parser_close
- * @return Aspect
+ * @return Cytro
*/
public function addBlockFunction($function, $callback, $parser_open = self::DEFAULT_FUNC_OPEN, $parser_close = self::DEFAULT_FUNC_CLOSE) {
$this->_actions[$function] = array(
@@ -410,7 +410,7 @@ class Aspect {
/**
* @param array $funcs
- * @return Aspect
+ * @return Cytro
*/
public function addAllowedFunctions(array $funcs) {
$this->_allowed_funcs = $this->_allowed_funcs + array_flip($funcs);
@@ -478,9 +478,9 @@ class Aspect {
* Add source template provider by scheme
*
* @param string $scm scheme name
- * @param Aspect\ProviderInterface $provider provider object
+ * @param Cytro\ProviderInterface $provider provider object
*/
- public function addProvider($scm, \Aspect\ProviderInterface $provider) {
+ public function addProvider($scm, \Cytro\ProviderInterface $provider) {
$this->_providers[$scm] = $provider;
}
@@ -511,7 +511,7 @@ class Aspect {
/**
* @param bool|string $scm
- * @return Aspect\ProviderInterface
+ * @return Cytro\ProviderInterface
* @throws InvalidArgumentException
*/
public function getProvider($scm = false) {
@@ -529,10 +529,10 @@ class Aspect {
/**
* Return empty template
*
- * @return Aspect\Template
+ * @return Cytro\Template
*/
public function getRawTemplate() {
- return new \Aspect\Template($this);
+ return new \Cytro\Template($this, $this->_options);
}
/**
@@ -540,7 +540,7 @@ class Aspect {
*
* @param string $template name of template
* @param array $vars array of data for template
- * @return Aspect\Render
+ * @return Cytro\Render
*/
public function display($template, array $vars = array()) {
return $this->getTemplate($template)->display($vars);
@@ -562,13 +562,13 @@ class Aspect {
*
* @param string $template
* @param int $options
- * @return Aspect\Template
+ * @return Cytro\Template
*/
public function getTemplate($template, $options = 0) {
$options = $this->_options | $options;
$key = $template.".".dechex($options);
if(isset($this->_storage[ $key ])) {
- /** @var Aspect\Template $tpl */
+ /** @var Cytro\Template $tpl */
$tpl = $this->_storage[ $key ];
if(($this->_options & self::AUTO_RELOAD) && !$tpl->isValid()) {
return $this->_storage[ $key ] = $this->compile($template, true, $options);
@@ -584,10 +584,10 @@ class Aspect {
/**
* Add custom template into storage
- * @param Aspect\Render $template
+ * @param Cytro\Render $template
*/
- public function addTemplate(Aspect\Render $template, $options = 0) {
- $this->_storage[ $template->getName().".".dechex($options) ] = $template;
+ public function addTemplate(Cytro\Render $template) {
+ $this->_storage[ $template->getName().".".dechex($template->getOptions()) ] = $template;
}
/**
@@ -595,7 +595,7 @@ class Aspect {
*
* @param string $tpl
* @param int $opts
- * @return Aspect\Render
+ * @return Cytro\Render
*/
protected function _load($tpl, $opts) {
$file_name = $this->_getCacheName($tpl, $opts);
@@ -624,14 +624,15 @@ class Aspect {
*
* @param string $tpl
* @param bool $store store template on disk
- * @param int $opts
+ * @param int $options
* @throws RuntimeException
- * @return \Aspect\Template
+ * @return \Cytro\Template
*/
- public function compile($tpl, $store = true, $opts = 0) {
- $template = Template::factory($this)->load($tpl);
+ public function compile($tpl, $store = true, $options = 0) {
+ $options = $this->_options | $options;
+ $template = Template::factory($this, $options)->load($tpl);
if($store) {
- $cache = $this->_getCacheName($tpl, $opts);
+ $cache = $this->_getCacheName($tpl, $options);
$tpl_tmp = tempnam($this->_compile_dir, $cache);
$tpl_fp = fopen($tpl_tmp, "w");
if(!$tpl_fp) {
@@ -673,7 +674,7 @@ class Aspect {
*
*/
public function clearAllCompiles() {
- \Aspect\FSProvider::clean($this->_compile_dir);
+ \Cytro\FSProvider::clean($this->_compile_dir);
}
/**
@@ -681,10 +682,10 @@ class Aspect {
*
* @param string $code
* @param string $name
- * @return Aspect\Template
+ * @return Cytro\Template
*/
public function compileCode($code, $name = 'Runtime compile') {
- return Template::factory($this)->source($name, $code);
+ return Template::factory($this, $this->_options)->source($name, $code);
}
diff --git a/src/Aspect/Compiler.php b/src/Cytro/Compiler.php
similarity index 97%
rename from src/Aspect/Compiler.php
rename to src/Cytro/Compiler.php
index fa4d78d..0946200 100644
--- a/src/Aspect/Compiler.php
+++ b/src/Cytro/Compiler.php
@@ -1,8 +1,8 @@
parseFirstArg($tokens, $name);
$p = $tpl->parseParams($tokens);
if($p) { // if we have additionally variables
- if($name && ($tpl->getStorage()->getOptions() & \Aspect::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
+ if($name && ($tpl->getStorage()->getOptions() & \Cytro::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
$inc = $tpl->getStorage()->compile($name, false);
$tpl->addDepend($inc);
return '$_tpl = (array)$tpl; $tpl->exchangeArray('.self::toArray($p).'+$_tpl); ?>'.$inc->_body.'exchangeArray($_tpl); unset($_tpl);';
@@ -29,7 +29,7 @@ class Compiler {
return '$tpl->getStorage()->getTemplate('.$cname.')->display('.self::toArray($p).'+(array)$tpl);';
}
} else {
- if($name && ($tpl->getStorage()->getOptions() & \Aspect::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
+ if($name && ($tpl->getStorage()->getOptions() & \Cytro::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
$inc = $tpl->getStorage()->compile($name, false);
$tpl->addDepend($inc);
return '$_tpl = (array)$tpl; ?>'.$inc->_body.'exchangeArray($_tpl); unset($_tpl);';
@@ -375,14 +375,19 @@ class Compiler {
if(empty($tpl->_extended)) {
$tpl->addPostCompile(__CLASS__."::extendBody");
}
+ /*if($tpl->getOptions() & Template::EXTENDED) {
+ $tpl->_compatible = true;
+ } else {
+ $tpl->_compatible = false;
+ }*/
if($name) { // static extends
$tpl->_extends = $tpl->getStorage()->getRawTemplate()->load($name, false);
$tpl->_compatible = &$tpl->_extends->_compatible;
- $tpl->addDepend($tpl->_extends); // for valid compile-time need take template from storage
+ $tpl->addDepend($tpl->_extends);
return "";
} else { // dynamic extends
$tpl->_extends = $tpl_name;
- return '$parent = $tpl->getStorage()->getTemplate('.$tpl_name.', \Aspect\Template::EXTENDED);';
+ return '$parent = $tpl->getStorage()->getTemplate('.$tpl_name.', \Cytro\Template::EXTENDED);';
}
}
diff --git a/src/Aspect/FSProvider.php b/src/Cytro/FSProvider.php
similarity index 98%
rename from src/Aspect/FSProvider.php
rename to src/Cytro/FSProvider.php
index a4154f7..27292fb 100644
--- a/src/Aspect/FSProvider.php
+++ b/src/Cytro/FSProvider.php
@@ -1,7 +1,7 @@
_aspect = $aspect;
$props += self::$_props;
$this->_name = $props["name"];
@@ -60,7 +62,7 @@ class Render extends \ArrayObject {
/**
* Get template storage
- * @return Aspect
+ * @return Cytro
*/
public function getStorage() {
return $this->_aspect;
@@ -82,6 +84,10 @@ class Render extends \ArrayObject {
return $this->_base_name;
}
+ public function getOptions() {
+ return $this->_options;
+ }
+
/**
* @return string
*/
diff --git a/src/Aspect/Scope.php b/src/Cytro/Scope.php
similarity index 99%
rename from src/Aspect/Scope.php
rename to src/Cytro/Scope.php
index 00b43d4..b7e65fa 100644
--- a/src/Aspect/Scope.php
+++ b/src/Cytro/Scope.php
@@ -1,5 +1,5 @@
_aspect = $aspect;
$this->_options = $this->_aspect->getOptions();
}
@@ -92,7 +86,7 @@ class Template extends Render {
* Load source from provider
* @param string $name
* @param bool $compile
- * @return \Aspect\Template
+ * @return \Cytro\Template
*/
public function load($name, $compile = true) {
$this->_name = $name;
@@ -115,7 +109,7 @@ class Template extends Render {
* @param string $name template name
* @param string $src template source
* @param bool $compile
- * @return \Aspect\Template
+ * @return \Cytro\Template
*/
public function source($name, $src, $compile = true) {
$this->_name = $name;
@@ -275,8 +269,8 @@ class Template extends Render {
*/
public function getTemplateCode() {
return "_name."' compiled at ".date('Y-m-d H:i:s')." */\n".
- "return new Aspect\\Render(\$aspect, ".$this->_getClosureSource().", ".var_export(array(
+ "/** Cytro template '".$this->_name."' compiled at ".date('Y-m-d H:i:s')." */\n".
+ "return new Cytro\\Render(\$aspect, ".$this->_getClosureSource().", ".var_export(array(
"options" => $this->_options,
"provider" => $this->_scm,
"name" => $this->_name,
@@ -422,18 +416,18 @@ class Template extends Render {
if($act = $this->_aspect->getFunction($action)) { // call some function
switch($act["type"]) {
- case Aspect::BLOCK_COMPILER:
+ case Cytro::BLOCK_COMPILER:
$scope = new Scope($action, $this, $this->_line, $act, count($this->_stack), $this->_body);
$code = $scope->open($tokens);
if(!$scope->is_closed) {
array_push($this->_stack, $scope);
}
return $code;
- case Aspect::INLINE_COMPILER:
+ case Cytro::INLINE_COMPILER:
return call_user_func($act["parser"], $tokens, $this);
- case Aspect::INLINE_FUNCTION:
+ case Cytro::INLINE_FUNCTION:
return call_user_func($act["parser"], $act["function"], $tokens, $this);
- case Aspect::BLOCK_FUNCTION:
+ case Cytro::BLOCK_FUNCTION:
$scope = new Scope($action, $this, $this->_line, $act, count($this->_stack), $this->_body);
$scope->setFuncName($act["function"]);
array_push($this->_stack, $scope);
@@ -641,7 +635,7 @@ class Template extends Render {
} elseif($t === T_OBJECT_OPERATOR) {
$prop = $tokens->getNext(T_STRING);
if($tokens->isNext("(")) {
- if($this->_options & Aspect::DENY_METHODS) {
+ if($this->_options & Cytro::DENY_METHODS) {
throw new \LogicException("Forbidden to call methods");
}
$pure_var = false;
diff --git a/src/Aspect/Tokenizer.php b/src/Cytro/Tokenizer.php
similarity index 99%
rename from src/Aspect/Tokenizer.php
rename to src/Cytro/Tokenizer.php
index e21ca81..f42d7c6 100644
--- a/src/Aspect/Tokenizer.php
+++ b/src/Cytro/Tokenizer.php
@@ -1,13 +1,13 @@
1,
+ "two" => 2,
+ "three" => 3,
+ 1 => "one value",
+ 2 => "two value",
+ 3 => "three value",
+ );
public function setUp() {
- if(!file_exists(ASPECT_RESOURCES.'/compile')) {
- mkdir(ASPECT_RESOURCES.'/compile', 0777, true);
+ if(!file_exists(CYTRO_RESOURCES.'/compile')) {
+ mkdir(CYTRO_RESOURCES.'/compile', 0777, true);
} else {
- FS::clean(ASPECT_RESOURCES.'/compile/');
+ FS::clean(CYTRO_RESOURCES.'/compile/');
}
- $this->aspect = Aspect::factory(ASPECT_RESOURCES.'/template', ASPECT_RESOURCES.'/compile');
+ $this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile');
}
public static function setUpBeforeClass() {
- if(!file_exists(ASPECT_RESOURCES.'/template')) {
- mkdir(ASPECT_RESOURCES.'/template', 0777, true);
+ if(!file_exists(CYTRO_RESOURCES.'/template')) {
+ mkdir(CYTRO_RESOURCES.'/template', 0777, true);
} else {
- FS::clean(ASPECT_RESOURCES.'/template/');
+ FS::clean(CYTRO_RESOURCES.'/template/');
}
}
public function tpl($name, $code) {
- file_put_contents(ASPECT_RESOURCES.'/template/'.$name, $code);
+ file_put_contents(CYTRO_RESOURCES.'/template/'.$name, $code);
}
/**
@@ -38,7 +47,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
* @param bool $dump dump source and result code (for debug)
*/
public function exec($code, $vars, $result, $dump = false) {
- $tpl = $this->aspect->compileCode($code, "runtime.tpl");
+ $tpl = $this->cytro->compileCode($code, "runtime.tpl");
if($dump) {
echo "\n========= DUMP BEGIN ===========\n".$code."\n--- to ---\n".$tpl->getBody()."\n========= DUMP END =============\n";
}
@@ -47,7 +56,7 @@ class TestCase extends \PHPUnit_Framework_TestCase {
public function execTpl($name, $code, $vars, $result, $dump = false) {
$this->tpl($name, $code);
- $tpl = $this->aspect->getTemplate($name);
+ $tpl = $this->cytro->getTemplate($name);
if($dump) {
echo "\n========= DUMP BEGIN ===========\n".$code."\n--- to ---\n".$tpl->getBody()."\n========= DUMP END =============\n";
}
@@ -59,20 +68,49 @@ class TestCase extends \PHPUnit_Framework_TestCase {
* @param string $code source of the template
* @param string $exception exception class
* @param string $message exception message
- * @param int $options Aspect's options
+ * @param int $options Cytro's options
*/
public function execError($code, $exception, $message, $options = 0) {
- $opt = $this->aspect->getOptions();
- $this->aspect->setOptions($options);
+ $opt = $this->cytro->getOptions();
+ $this->cytro->setOptions($options);
try {
- $this->aspect->compileCode($code, "inline.tpl");
+ $this->cytro->compileCode($code, "inline.tpl");
} catch(\Exception $e) {
$this->assertSame($exception, get_class($e), "Exception $code");
$this->assertStringStartsWith($message, $e->getMessage());
- $this->aspect->setOptions($opt);
+ $this->cytro->setOptions($opt);
return;
}
- self::$aspect->setOptions($opt);
+ $this->cytro->setOptions($opt);
$this->fail("Code $code must be invalid");
}
+
+ public function assertRender($tpl, $result) {
+ $template = $this->cytro->compileCode($tpl);
+ $this->assertSame($result, $template->fetch($this->values));
+ }
+}
+
+class Fake implements \ArrayAccess {
+ public $vars;
+
+ public function offsetExists($offset) {
+ return true;
+ }
+
+ public function offsetGet($offset) {
+ if($offset == "object") {
+ return new self();
+ } else {
+ return new self($offset);
+ }
+ }
+
+ public function offsetSet($offset, $value) {
+ $this->vars[$offset] = $value;
+ }
+
+ public function offsetUnset($offset) {
+ unset($this->vars[$offset]);
+ }
}
diff --git a/tests/autoload.php b/tests/autoload.php
index fda7597..0dac5e6 100644
--- a/tests/autoload.php
+++ b/tests/autoload.php
@@ -4,9 +4,9 @@ require_once __DIR__."/../vendor/autoload.php";
-define('ASPECT_RESOURCES', __DIR__."/resources");
+define('CYTRO_RESOURCES', __DIR__."/resources");
-require_once ASPECT_RESOURCES."/actions.php";
+require_once CYTRO_RESOURCES."/actions.php";
require_once __DIR__."/TestCase.php";
function drop() {
diff --git a/tests/cases/Aspect/CustomProvider.php b/tests/cases/Aspect/CustomProvider.php
new file mode 100644
index 0000000..d3aed7a
--- /dev/null
+++ b/tests/cases/Aspect/CustomProvider.php
@@ -0,0 +1,17 @@
+setUp();
+ $this->cytro->addProvider("my", new FSProvider(CYTRO_RESOURCES.'/provider'));
+ }
+
+ public function testCustom() {
+ $this->render("start: {include 'my:include.tpl'}", 'start: include template');
+ $this->render("start: {import 'my:macros.tpl' as ops} {ops.add a=3 b=6}");
+ }
+}
\ No newline at end of file
diff --git a/tests/cases/Aspect/ExtendsTemplateTest.php b/tests/cases/Aspect/ExtendsTemplateTest.php
index d0d6ceb..45ccfb4 100644
--- a/tests/cases/Aspect/ExtendsTemplateTest.php
+++ b/tests/cases/Aspect/ExtendsTemplateTest.php
@@ -1,10 +1,11 @@
1, "two" => 2, "three" => 3);
+
+ public static function providerExtends($items) {
return array(
array("parent.tpl", "Parent. B1: {block b1}{/block}\nB2: {block 'b2'}empty {\$iteration}{/block}", $a,
"Parent. B1: \nB2: empty 0"),
@@ -23,6 +24,10 @@ class ExtendsTemplateTest extends TestCase {
return $data;
}
+ public function setUp() {
+ $this->cytro = Cytro::factory(CYTRO_RESOURCES.'/template', CYTRO_RESOURCES.'/compile');
+ }
+
/**
* @dataProvider providerExtends
* @param $name
@@ -30,7 +35,7 @@ class ExtendsTemplateTest extends TestCase {
* @param $vars
* @param $result
*/
- public function testStaticExtends($name, $code, $vars, $result) {
+ public function _testStaticExtends($name, $code, $vars, $result) {
static $i = 0;
$vars["iteration"] = $i++;
$this->execTpl($name, $code, $vars, $result);
@@ -43,7 +48,7 @@ class ExtendsTemplateTest extends TestCase {
* @param $vars
* @param $result
*/
- public function testDynamicExtends($name, $code, $vars, $result) {
+ public function _testDynamicExtends($name, $code, $vars, $result) {
static $i = 0;
$vars["iteration"] = $i++;
$this->execTpl($name, $code, $vars, $result, 0);
@@ -54,7 +59,7 @@ class ExtendsTemplateTest extends TestCase {
*/
public function _testParentLevel() {
//echo($this->aspect->getTemplate("parent.tpl")->_body); exit;
- $this->assertSame($this->aspect->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default");
+ $this->assertSame($this->cytro->fetch("parent.tpl", array("a" => "a char")), "Parent template\nBlock1: Block2: Block3: default");
}
/**
@@ -68,7 +73,7 @@ class ExtendsTemplateTest extends TestCase {
* @group extends
*/
public function _testChildLevel3() {
- echo($this->aspect->getTemplate("child3.tpl")->getBody()); exit;
+ echo($this->cytro->getTemplate("child3.tpl")->getBody()); exit;
}
}
diff --git a/tests/cases/Aspect/MacrosTest.php b/tests/cases/Aspect/MacrosTest.php
index a1b93f9..f40c0c5 100644
--- a/tests/cases/Aspect/MacrosTest.php
+++ b/tests/cases/Aspect/MacrosTest.php
@@ -1,5 +1,5 @@
aspect->compile('math.tpl');
+ $tpl = $this->cytro->compile('math.tpl');
$this->assertStringStartsWith('x + y = ', trim($tpl->macros["plus"]["body"]));
$this->assertSame('Math: x + y = 5 , x - y - z = 6', Modifier::strip($tpl->fetch(array()), true));
}
public function testImport() {
- $tpl = $this->aspect->compile('import.tpl');
+ $tpl = $this->cytro->compile('import.tpl');
$this->assertSame('Imp: x + y = 3 , x - y - z = 3', Modifier::strip($tpl->fetch(array()), true));
}
public function testImportCustom() {
- $tpl = $this->aspect->compile('import_custom.tpl');
+ $tpl = $this->cytro->compile('import_custom.tpl');
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
}
/**
* @expectedExceptionMessage Undefined macro 'plus'
- * @expectedException \Aspect\CompileException
+ * @expectedException \Cytro\CompileException
*/
public function testImportMiss() {
- $tpl = $this->aspect->compile('import_miss.tpl');
+ $tpl = $this->cytro->compile('import_miss.tpl');
$this->assertSame('a: x + y = 3 , x - y - z = 3 , new minus macros .', Modifier::strip($tpl->fetch(array()), true));
}
diff --git a/tests/cases/Aspect/ModifiersTest.php b/tests/cases/Aspect/ModifiersTest.php
index d0b8ac0..4fed699 100644
--- a/tests/cases/Aspect/ModifiersTest.php
+++ b/tests/cases/Aspect/ModifiersTest.php
@@ -1,5 +1,5 @@
aspect->compileCode('{$text|truncate:$count:$delim:$by_words:$middle}');
+ $tpl = $this->cytro->compileCode('{$text|truncate:$count:$delim:$by_words:$middle}');
$this->assertEquals($out, $tpl->fetch(array(
"text" => $in,
"count" => $count,
diff --git a/tests/cases/Aspect/ProviderTest.php b/tests/cases/Aspect/ProviderTest.php
index 52d0ede..241d02e 100644
--- a/tests/cases/Aspect/ProviderTest.php
+++ b/tests/cases/Aspect/ProviderTest.php
@@ -1,8 +1,8 @@
tpl("template1.tpl", 'Template 1 {$a}');
$this->tpl("template2.tpl", 'Template 2 {$a}');
- $this->provider = new FSProvider(ASPECT_RESOURCES.'/template');
+ $this->provider = new FSProvider(CYTRO_RESOURCES.'/template');
}
public function testIsTemplateExists() {
@@ -23,8 +23,8 @@ class FSProviderTest extends \Aspect\TestCase {
public function testGetSource() {
$src = $this->provider->getSource("template1.tpl", $time);
clearstatcache();
- $this->assertEquals(file_get_contents(ASPECT_RESOURCES.'/template/template1.tpl'), $src);
- $this->assertEquals(filemtime(ASPECT_RESOURCES.'/template/template1.tpl'), $time);
+ $this->assertEquals(file_get_contents(CYTRO_RESOURCES.'/template/template1.tpl'), $src);
+ $this->assertEquals(filemtime(CYTRO_RESOURCES.'/template/template1.tpl'), $time);
}
/**
@@ -37,7 +37,7 @@ class FSProviderTest extends \Aspect\TestCase {
public function testGetLastModified() {
$time = $this->provider->getLastModified("template1.tpl");
clearstatcache();
- $this->assertEquals(filemtime(ASPECT_RESOURCES.'/template/template1.tpl'), $time);
+ $this->assertEquals(filemtime(CYTRO_RESOURCES.'/template/template1.tpl'), $time);
}
/**
@@ -52,7 +52,7 @@ class FSProviderTest extends \Aspect\TestCase {
$this->assertSame($tpls, array_keys($times));
clearstatcache();
foreach($times as $template => $time) {
- $this->assertEquals(filemtime(ASPECT_RESOURCES."/template/$template"), $time);
+ $this->assertEquals(filemtime(CYTRO_RESOURCES."/template/$template"), $time);
}
}
diff --git a/tests/cases/Aspect/RenderTest.php b/tests/cases/Aspect/RenderTest.php
index bcd6200..6ec1134 100644
--- a/tests/cases/Aspect/RenderTest.php
+++ b/tests/cases/Aspect/RenderTest.php
@@ -1,7 +1,7 @@
"render.tpl"
@@ -19,7 +19,7 @@ class RenderTest extends \PHPUnit_Framework_TestCase {
}
public function testCreate() {
- $r = new Render(Aspect::factory("."), function () {
+ $r = new Render(Cytro::factory("."), function () {
echo "Test render";
}, array(
"name" => "test.render.tpl"
@@ -43,7 +43,7 @@ class RenderTest extends \PHPUnit_Framework_TestCase {
* @expectedExceptionMessage template error
*/
public function testFetchException() {
- $render = new Render(Aspect::factory("."), function () {
+ $render = new Render(Cytro::factory("."), function () {
echo "error";
throw new \RuntimeException("template error");
}, array(
diff --git a/tests/cases/Aspect/ScopeTest.php b/tests/cases/Aspect/ScopeTest.php
index efacbc3..05eb8c2 100644
--- a/tests/cases/Aspect/ScopeTest.php
+++ b/tests/cases/Aspect/ScopeTest.php
@@ -1,17 +1,17 @@
assertInstanceOf('Aspect\Tokenizer', $tokenizer);
- $this->assertInstanceOf('Aspect\Scope', $scope);
+ $this->assertInstanceOf('Cytro\Tokenizer', $tokenizer);
+ $this->assertInstanceOf('Cytro\Scope', $scope);
$scope["value"] = true;
return "open-tag";
}
public function closeTag($tokenizer, $scope) {
- $this->assertInstanceOf('Aspect\Tokenizer', $tokenizer);
- $this->assertInstanceOf('Aspect\Scope', $scope);
+ $this->assertInstanceOf('Cytro\Tokenizer', $tokenizer);
+ $this->assertInstanceOf('Cytro\Scope', $scope);
$this->assertTrue($scope["value"]);
return "close-tag";
}
diff --git a/tests/cases/Aspect/TemplateTest.php b/tests/cases/Aspect/TemplateTest.php
index 7f2ee93..7190074 100644
--- a/tests/cases/Aspect/TemplateTest.php
+++ b/tests/cases/Aspect/TemplateTest.php
@@ -1,14 +1,14 @@
aspect->addTemplate(new Render($this->aspect, function ($tpl) {
+ $this->cytro->addTemplate(new Render($this->cytro, function ($tpl) {
echo "Welcome, ".$tpl["username"]." (".$tpl["email"].")";
}, array(
"name" => "welcome.tpl"
@@ -111,14 +111,14 @@ class TemplateTest extends TestCase {
public static function providerVarsInvalid() {
return array(
- array('hello, {$a.}!', 'Aspect\CompileException', "Unexpected end of expression"),
- array('hello, {$b[c}!', 'Aspect\CompileException', "Unexpected end of expression"),
- array('hello, {$b.c]}!', 'Aspect\CompileException', "Unexpected token ']'"),
- array('hello, {$b[ ]}!', 'Aspect\CompileException', "Unexpected token ']'"),
- array('hello, {$b[9/].c}!', 'Aspect\CompileException', "Unexpected token ']'"),
- array('hello, {$b[3]$c}!', 'Aspect\CompileException', "Unexpected token '\$c'"),
- array('hello, {$b[3]c}!', 'Aspect\CompileException', "Unexpected token 'c'"),
- array('hello, {$b.obj->valid()}!', 'Aspect\SecurityException', "Forbidden to call methods", Aspect::DENY_METHODS),
+ array('hello, {$a.}!', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('hello, {$b[c}!', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('hello, {$b.c]}!', 'Cytro\CompileException', "Unexpected token ']'"),
+ array('hello, {$b[ ]}!', 'Cytro\CompileException', "Unexpected token ']'"),
+ array('hello, {$b[9/].c}!', 'Cytro\CompileException', "Unexpected token ']'"),
+ array('hello, {$b[3]$c}!', 'Cytro\CompileException', "Unexpected token '\$c'"),
+ array('hello, {$b[3]c}!', 'Cytro\CompileException', "Unexpected token 'c'"),
+ array('hello, {$b.obj->valid()}!', 'Cytro\SecurityException', "Forbidden to call methods", Cytro::DENY_METHODS),
);
}
@@ -173,12 +173,12 @@ class TemplateTest extends TestCase {
public static function providerModifiersInvalid() {
return array(
- array('Mod: {$lorem|}!', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Mod: {$lorem|str_rot13}!', 'Aspect\CompileException', "Modifier str_rot13 not found", Aspect::DENY_INLINE_FUNCS),
- array('Mod: {$lorem|my_encode}!', 'Aspect\CompileException', "Modifier my_encode not found"),
- array('Mod: {$lorem|truncate:}!', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Mod: {$lorem|truncate:abs}!', 'Aspect\CompileException', "Unexpected token 'abs'"),
- array('Mod: {$lorem|truncate:80|}!', 'Aspect\CompileException', "Unexpected end of expression"),
+ array('Mod: {$lorem|}!', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Mod: {$lorem|str_rot13}!', 'Cytro\CompileException', "Modifier str_rot13 not found", Cytro::DENY_INLINE_FUNCS),
+ array('Mod: {$lorem|my_encode}!', 'Cytro\CompileException', "Modifier my_encode not found"),
+ array('Mod: {$lorem|truncate:}!', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Mod: {$lorem|truncate:abs}!', 'Cytro\CompileException', "Unexpected token 'abs'"),
+ array('Mod: {$lorem|truncate:80|}!', 'Cytro\CompileException', "Unexpected end of expression"),
);
}
@@ -220,15 +220,15 @@ class TemplateTest extends TestCase {
public static function providerExpressionsInvalid() {
return array(
- array('If: {-"hi"} end', 'Aspect\CompileException', "Unexpected token '-'"),
- array('If: {($a++)++} end', 'Aspect\CompileException', "Unexpected token '++'"),
- array('If: {$a + * $c} end', 'Aspect\CompileException', "Unexpected token '*'"),
- array('If: {/$a} end', 'Aspect\CompileException', "Unexpected token '\$a'"),
- array('If: {$a == 5 > 4} end', 'Aspect\CompileException', "Unexpected token '>'"),
- array('If: {$a != 5 <= 4} end', 'Aspect\CompileException', "Unexpected token '<='"),
- array('If: {$a != 5 => 4} end', 'Aspect\CompileException', "Unexpected token '=>'"),
- array('If: {$a + (*6)} end', 'Aspect\CompileException', "Unexpected token '*'"),
- array('If: {$a + ( 6} end', 'Aspect\CompileException', "Brackets don't match"),
+ array('If: {-"hi"} end', 'Cytro\CompileException', "Unexpected token '-'"),
+ array('If: {($a++)++} end', 'Cytro\CompileException', "Unexpected token '++'"),
+ array('If: {$a + * $c} end', 'Cytro\CompileException', "Unexpected token '*'"),
+ array('If: {/$a} end', 'Cytro\CompileException', "Unexpected token '\$a'"),
+ array('If: {$a == 5 > 4} end', 'Cytro\CompileException', "Unexpected token '>'"),
+ array('If: {$a != 5 <= 4} end', 'Cytro\CompileException', "Unexpected token '<='"),
+ array('If: {$a != 5 => 4} end', 'Cytro\CompileException', "Unexpected token '=>'"),
+ array('If: {$a + (*6)} end', 'Cytro\CompileException', "Unexpected token '*'"),
+ array('If: {$a + ( 6} end', 'Cytro\CompileException', "Brackets don't match"),
);
}
@@ -265,8 +265,8 @@ class TemplateTest extends TestCase {
public static function providerIncludeInvalid() {
return array(
- array('Include {include} template', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Include {include another="welcome.tpl"} template', 'Aspect\CompileException', "Unexpected token '='"),
+ array('Include {include} template', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Include {include another="welcome.tpl"} template', 'Cytro\CompileException', "Unexpected token '='"),
);
}
@@ -306,10 +306,10 @@ class TemplateTest extends TestCase {
public static function providerIfInvalid() {
return array(
- array('If: {if} block1 {/if} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('If: {if 1} block1 {elseif} block2 {/if} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('If: {if 1} block1 {else} block2 {elseif 0} block3 {/if} end', 'Aspect\CompileException', "Incorrect use of the tag {elseif}"),
- array('If: {if 1} block1 {else} block2 {/if} block3 {elseif 0} end', 'Aspect\CompileException', "Unexpected tag 'elseif' (this tag can be used with 'if')"),
+ array('If: {if} block1 {/if} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('If: {if 1} block1 {elseif} block2 {/if} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('If: {if 1} block1 {else} block2 {elseif 0} block3 {/if} end', 'Cytro\CompileException', "Incorrect use of the tag {elseif}"),
+ array('If: {if 1} block1 {else} block2 {/if} block3 {elseif 0} end', 'Cytro\CompileException', "Unexpected tag 'elseif' (this tag can be used with 'if')"),
);
}
@@ -347,20 +347,20 @@ class TemplateTest extends TestCase {
public static function providerCreateVarInvalid() {
return array(
- array('Create: {var $v} Result: {$v} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Create: {var $v = } Result: {$v} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Create: {var $v = 1++} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '++'"),
- array('Create: {var $v = c} Result: {$v} end', 'Aspect\CompileException', "Unexpected token 'c'"),
- array('Create: {var $v = ($a)++} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '++'"),
- array('Create: {var $v = --$a++} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '++'"),
- array('Create: {var $v = $a|upper++} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '++'"),
- array('Create: {var $v = max($a,2)++} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '++'"),
- array('Create: {var $v = max($a,2)} Result: {$v} end', 'Aspect\CompileException', "Modifier max not found", Aspect::DENY_INLINE_FUNCS),
- array('Create: {var $v = 4*} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '*'"),
- array('Create: {var $v = ""$a} Result: {$v} end', 'Aspect\CompileException', "Unexpected token '\$a'"),
- array('Create: {var $v = [1,2} Result: {$v} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Create: {var $v = empty(2)} Result: {$v} end', 'Aspect\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
- array('Create: {var $v = isset(2)} Result: {$v} end', 'Aspect\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
+ array('Create: {var $v} Result: {$v} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Create: {var $v = } Result: {$v} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Create: {var $v = 1++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
+ array('Create: {var $v = c} Result: {$v} end', 'Cytro\CompileException', "Unexpected token 'c'"),
+ array('Create: {var $v = ($a)++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
+ array('Create: {var $v = --$a++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
+ array('Create: {var $v = $a|upper++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
+ array('Create: {var $v = max($a,2)++} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '++'"),
+ array('Create: {var $v = max($a,2)} Result: {$v} end', 'Cytro\CompileException', "Modifier max not found", Cytro::DENY_INLINE_FUNCS),
+ array('Create: {var $v = 4*} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '*'"),
+ array('Create: {var $v = ""$a} Result: {$v} end', 'Cytro\CompileException', "Unexpected token '\$a'"),
+ array('Create: {var $v = [1,2} Result: {$v} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Create: {var $v = empty(2)} Result: {$v} end', 'Cytro\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
+ array('Create: {var $v = isset(2)} Result: {$v} end', 'Cytro\CompileException', "Unexpected token 2, isset() and empty() accept only variables"),
);
}
@@ -453,27 +453,27 @@ class TemplateTest extends TestCase {
public static function providerForeachInvalid() {
return array(
- array('Foreach: {foreach} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected end of tag {foreach}"),
- array('Foreach: {foreach $list} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Foreach: {foreach $list+1 as $e} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('Foreach: {foreach array_random() as $e} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'array_random'"),
- array('Foreach: {foreach $list as $e+1} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('Foreach: {foreach $list as $k+1 => $e} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('Foreach: {foreach $list as max($i,1) => $e} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'max'"),
- array('Foreach: {foreach $list as max($e,1)} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'max'"),
- array('Foreach: {foreach $list => $e} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '=>'"),
- array('Foreach: {foreach $list $k => $e} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '\$k'"),
- array('Foreach: {foreach $list as $k =>} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Foreach: {foreach last=$l $list as $e } {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'last' in tag {foreach}"),
- array('Foreach: {foreach $list as $e unknown=1} {$e}, {/foreach} end', 'Aspect\CompileException', "Unknown parameter 'unknown'"),
- array('Foreach: {foreach $list as $e index=$i+1} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('Foreach: {foreach $list as $e first=$f+1} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('Foreach: {foreach $list as $e last=$l+1} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('Foreach: {foreach $list as $e index=max($i,1)} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'max'"),
- array('Foreach: {foreach $list as $e first=max($i,1)} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'max'"),
- array('Foreach: {foreach $list as $e last=max($i,1)} {$e}, {/foreach} end', 'Aspect\CompileException', "Unexpected token 'max'"),
- array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {break} {/foreach} end', 'Aspect\CompileException', "Improper usage of the tag {break}"),
- array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {continue} {/foreach} end', 'Aspect\CompileException', "Improper usage of the tag {continue}"),
+ array('Foreach: {foreach} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected end of tag {foreach}"),
+ array('Foreach: {foreach $list} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Foreach: {foreach $list+1 as $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('Foreach: {foreach array_random() as $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'array_random'"),
+ array('Foreach: {foreach $list as $e+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('Foreach: {foreach $list as $k+1 => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('Foreach: {foreach $list as max($i,1) => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
+ array('Foreach: {foreach $list as max($e,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
+ array('Foreach: {foreach $list => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '=>'"),
+ array('Foreach: {foreach $list $k => $e} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '\$k'"),
+ array('Foreach: {foreach $list as $k =>} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Foreach: {foreach last=$l $list as $e } {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'last' in tag {foreach}"),
+ array('Foreach: {foreach $list as $e unknown=1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unknown parameter 'unknown'"),
+ array('Foreach: {foreach $list as $e index=$i+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('Foreach: {foreach $list as $e first=$f+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('Foreach: {foreach $list as $e last=$l+1} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('Foreach: {foreach $list as $e index=max($i,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
+ array('Foreach: {foreach $list as $e first=max($i,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
+ array('Foreach: {foreach $list as $e last=max($i,1)} {$e}, {/foreach} end', 'Cytro\CompileException', "Unexpected token 'max'"),
+ array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {break} {/foreach} end', 'Cytro\CompileException', "Improper usage of the tag {break}"),
+ array('Foreach: {foreach $list as $e} {$e}, {foreachelse} {continue} {/foreach} end', 'Cytro\CompileException', "Improper usage of the tag {continue}"),
);
}
@@ -518,9 +518,9 @@ class TemplateTest extends TestCase {
public static function providerSwitchInvalid() {
return array(
- array('Switch: {switch}{case 1} one {break}{/switch} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Switch: {switch 1}{case} one {break}{/switch} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('Switch: {switch 1}{break}{case} one {/switch} end', 'Aspect\CompileException', "Improper usage of the tag {break}"),
+ array('Switch: {switch}{case 1} one {break}{/switch} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Switch: {switch 1}{case} one {break}{/switch} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('Switch: {switch 1}{break}{case} one {/switch} end', 'Cytro\CompileException', "Improper usage of the tag {break}"),
);
}
@@ -536,7 +536,7 @@ class TemplateTest extends TestCase {
public static function providerWhileInvalid() {
return array(
- array('While: {while} block {/while} end', 'Aspect\CompileException', "Unexpected end of expression"),
+ array('While: {while} block {/while} end', 'Cytro\CompileException', "Unexpected end of expression"),
);
}
@@ -564,29 +564,29 @@ class TemplateTest extends TestCase {
public static function providerForInvalid() {
return array(
- array('For: {for} block1 {/for} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('For: {for $a=} block1 {/for} end', 'Aspect\CompileException', "Unexpected end of expression"),
- array('For: {for $a+1=3 to=6} block1 {/for} end', 'Aspect\CompileException', "Unexpected token '+'"),
- array('For: {for max($a,$b)=3 to=6} block1 {/for} end', 'Aspect\CompileException', "Unexpected token 'max'"),
- array('For: {for to=6 $a=3} block1 {/for} end', 'Aspect\CompileException', "Unexpected token 'to'"),
- array('For: {for index=$i $a=3 to=6} block1 {/for} end', 'Aspect\CompileException', "Unexpected token 'index'"),
- array('For: {for first=$i $a=3 to=6} block1 {/for} end', 'Aspect\CompileException', "Unexpected token 'first'"),
- array('For: {for last=$i $a=3 to=6} block1 {/for} end', 'Aspect\CompileException', "Unexpected token 'last'"),
- array('For: {for $a=4 to=6 unk=4} block1 {/for} end', 'Aspect\CompileException', "Unknown parameter 'unk'"),
- array('For: {for $a=4 to=6} $a: {$a}, {forelse} {break} {/for} end', 'Aspect\CompileException', "Improper usage of the tag {break}"),
- array('For: {for $a=4 to=6} $a: {$a}, {forelse} {continue} {/for} end', 'Aspect\CompileException', "Improper usage of the tag {continue}"),
+ array('For: {for} block1 {/for} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('For: {for $a=} block1 {/for} end', 'Cytro\CompileException', "Unexpected end of expression"),
+ array('For: {for $a+1=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token '+'"),
+ array('For: {for max($a,$b)=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'max'"),
+ array('For: {for to=6 $a=3} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'to'"),
+ array('For: {for index=$i $a=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'index'"),
+ array('For: {for first=$i $a=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'first'"),
+ array('For: {for last=$i $a=3 to=6} block1 {/for} end', 'Cytro\CompileException', "Unexpected token 'last'"),
+ array('For: {for $a=4 to=6 unk=4} block1 {/for} end', 'Cytro\CompileException', "Unknown parameter 'unk'"),
+ array('For: {for $a=4 to=6} $a: {$a}, {forelse} {break} {/for} end', 'Cytro\CompileException', "Improper usage of the tag {break}"),
+ array('For: {for $a=4 to=6} $a: {$a}, {forelse} {continue} {/for} end', 'Cytro\CompileException', "Improper usage of the tag {continue}"),
);
}
public static function providerLayersInvalid() {
return array(
- array('Layers: {foreach $list as $e} block1 {if 1} {foreachelse} {/if} {/foreach} end', 'Aspect\CompileException', "Unexpected tag 'foreachelse' (this tag can be used with 'foreach')"),
- array('Layers: {foreach $list as $e} block1 {if 1} {/foreach} {/if} end', 'Aspect\CompileException', "Unexpected closing of the tag 'foreach'"),
- array('Layers: {for $a=4 to=6} block1 {if 1} {forelse} {/if} {/for} end', 'Aspect\CompileException', "Unexpected tag 'forelse' (this tag can be used with 'for')"),
- array('Layers: {for $a=4 to=6} block1 {if 1} {/for} {/if} end', 'Aspect\CompileException', "Unexpected closing of the tag 'for'"),
- array('Layers: {switch 1} {if 1} {case 1} {/if} {/switch} end', 'Aspect\CompileException', "Unexpected tag 'case' (this tag can be used with 'switch')"),
- array('Layers: {/switch} end', 'Aspect\CompileException', "Unexpected closing of the tag 'switch'"),
- array('Layers: {if 1} end', 'Aspect\CompileException', "Unclosed tag(s): {if}"),
+ array('Layers: {foreach $list as $e} block1 {if 1} {foreachelse} {/if} {/foreach} end', 'Cytro\CompileException', "Unexpected tag 'foreachelse' (this tag can be used with 'foreach')"),
+ array('Layers: {foreach $list as $e} block1 {if 1} {/foreach} {/if} end', 'Cytro\CompileException', "Unexpected closing of the tag 'foreach'"),
+ array('Layers: {for $a=4 to=6} block1 {if 1} {forelse} {/if} {/for} end', 'Cytro\CompileException', "Unexpected tag 'forelse' (this tag can be used with 'for')"),
+ array('Layers: {for $a=4 to=6} block1 {if 1} {/for} {/if} end', 'Cytro\CompileException', "Unexpected closing of the tag 'for'"),
+ array('Layers: {switch 1} {if 1} {case 1} {/if} {/switch} end', 'Cytro\CompileException', "Unexpected tag 'case' (this tag can be used with 'switch')"),
+ array('Layers: {/switch} end', 'Cytro\CompileException', "Unexpected closing of the tag 'switch'"),
+ array('Layers: {if 1} end', 'Cytro\CompileException', "Unclosed tag(s): {if}"),
);
}
diff --git a/tests/cases/Aspect/TokenizerTest.php b/tests/cases/Aspect/TokenizerTest.php
index 2277901..95ef149 100644
--- a/tests/cases/Aspect/TokenizerTest.php
+++ b/tests/cases/Aspect/TokenizerTest.php
@@ -1,6 +1,6 @@
skip(T_STRING)->skip('(')->skip(':');
} catch(\Exception $e) {
- $this->assertInstanceOf('Aspect\UnexpectedTokenException', $e);
+ $this->assertInstanceOf('Cytro\UnexpectedTokenException', $e);
$this->assertStringStartsWith("Unexpected token '3' in expression, expect ':'", $e->getMessage());
}
$this->assertTrue($tokens->valid());
diff --git a/tests/cases/AspectTest.php b/tests/cases/AspectTest.php
index 2d8590c..1b4f744 100644
--- a/tests/cases/AspectTest.php
+++ b/tests/cases/AspectTest.php
@@ -1,22 +1,22 @@
aspect->addTemplate(new Render($this->aspect, function($tpl) use ($test) {
+ $this->cytro->addTemplate(new Render($this->cytro, function($tpl) use ($test) {
/** @var \PHPUnit_Framework_TestCase $test */
- $test->assertInstanceOf('Aspect\Render', $tpl);
+ $test->assertInstanceOf('Cytro\Render', $tpl);
echo "Inline render";
}, array(
"name" => 'render.tpl',
"scm" => false
)));
- $this->assertSame("Inline render", $this->aspect->fetch('render.tpl', array()));
+ $this->assertSame("Inline render", $this->cytro->fetch('render.tpl', array()));
}
public function testCompileFile() {
@@ -26,71 +26,71 @@ class AspectTest extends \Aspect\TestCase {
);
$this->tpl('template1.tpl', 'Template 1 a');
$this->tpl('template2.tpl', 'Template 2 b');
- $this->assertSame("Template 1 a", $this->aspect->fetch('template1.tpl', $a));
- $this->assertSame("Template 2 b", $this->aspect->fetch('template2.tpl', $a));
- $this->assertInstanceOf('Aspect\Render', $this->aspect->getTemplate('template1.tpl'));
- $this->assertInstanceOf('Aspect\Render', $this->aspect->getTemplate('template2.tpl'));
- $this->assertSame(3, iterator_count(new FilesystemIterator(ASPECT_RESOURCES.'/compile')));
+ $this->assertSame("Template 1 a", $this->cytro->fetch('template1.tpl', $a));
+ $this->assertSame("Template 2 b", $this->cytro->fetch('template2.tpl', $a));
+ $this->assertInstanceOf('Cytro\Render', $this->cytro->getTemplate('template1.tpl'));
+ $this->assertInstanceOf('Cytro\Render', $this->cytro->getTemplate('template2.tpl'));
+ $this->assertSame(3, iterator_count(new FilesystemIterator(CYTRO_RESOURCES.'/compile')));
}
public function testStorage() {
$this->tpl('custom.tpl', 'Custom template');
- $this->assertSame("Custom template", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
//$this->aspect->clearCompiledTemplate('custom.tpl', false);
//$this->assertSame("Custom template", $this->aspect->fetch('custom.tpl', array()));
$this->tpl('custom.tpl', 'Custom template 2');
- $this->assertSame("Custom template", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
}
public function testCheckMTime() {
- $this->aspect->setOptions(Aspect::FORCE_COMPILE);
+ $this->cytro->setOptions(Cytro::FORCE_COMPILE);
$this->tpl('custom.tpl', 'Custom template');
- $this->assertSame("Custom template", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
sleep(1);
$this->tpl('custom.tpl', 'Custom template (new)');
- $this->assertSame("Custom template (new)", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom template (new)", $this->cytro->fetch('custom.tpl', array()));
}
public function testForceCompile() {
- $this->aspect->setOptions(Aspect::FORCE_COMPILE);
+ $this->cytro->setOptions(Cytro::FORCE_COMPILE);
$this->tpl('custom.tpl', 'Custom template');
- $this->assertSame("Custom template", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom template", $this->cytro->fetch('custom.tpl', array()));
$this->tpl('custom.tpl', 'Custom template (new)');
- $this->assertSame("Custom template (new)", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom template (new)", $this->cytro->fetch('custom.tpl', array()));
}
public function testSetModifier() {
- $this->aspect->addModifier("mymod", "myMod");
+ $this->cytro->addModifier("mymod", "myMod");
$this->tpl('custom.tpl', 'Custom modifier {$a|mymod}');
- $this->assertSame("Custom modifier (myMod)Custom(/myMod)", $this->aspect->fetch('custom.tpl', array("a" => "Custom")));
+ $this->assertSame("Custom modifier (myMod)Custom(/myMod)", $this->cytro->fetch('custom.tpl', array("a" => "Custom")));
}
/**
* @group add_functions
*/
public function testSetFunctions() {
- $this->aspect->setOptions(Aspect::FORCE_COMPILE);
- $this->aspect->addFunction("myfunc", "myFunc");
- $this->aspect->addBlockFunction("myblockfunc", "myBlockFunc");
+ $this->cytro->setOptions(Cytro::FORCE_COMPILE);
+ $this->cytro->addFunction("myfunc", "myFunc");
+ $this->cytro->addBlockFunction("myblockfunc", "myBlockFunc");
$this->tpl('custom.tpl', 'Custom function {myfunc name="foo"}');
- $this->assertSame("Custom function MyFunc:foo", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom function MyFunc:foo", $this->cytro->fetch('custom.tpl', array()));
$this->tpl('custom.tpl', 'Custom function {myblockfunc name="foo"} this block1 {/myblockfunc}');
- $this->assertSame("Custom function Block:foo:this block1:Block", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom function Block:foo:this block1:Block", $this->cytro->fetch('custom.tpl', array()));
}
public function testSetCompilers() {
- $this->aspect->setOptions(Aspect::FORCE_COMPILE);
- $this->aspect->addCompiler("mycompiler", 'myCompiler');
- $this->aspect->addBlockCompiler("myblockcompiler", 'myBlockCompilerOpen', 'myBlockCompilerClose', array(
+ $this->cytro->setOptions(Cytro::FORCE_COMPILE);
+ $this->cytro->addCompiler("mycompiler", 'myCompiler');
+ $this->cytro->addBlockCompiler("myblockcompiler", 'myBlockCompilerOpen', 'myBlockCompilerClose', array(
'tag' => 'myBlockCompilerTag'
));
$this->tpl('custom.tpl', 'Custom compiler {mycompiler name="bar"}');
- $this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar)", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar)", $this->cytro->fetch('custom.tpl', array()));
$this->tpl('custom.tpl', 'Custom compiler {myblockcompiler name="bar"} block1 {tag name="baz"} block2 {/myblockcompiler}');
- $this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar) block1 Tag baz of compiler block2 End of compiler", $this->aspect->fetch('custom.tpl', array()));
+ $this->assertSame("Custom compiler PHP_VERSION: ".PHP_VERSION." (for bar) block1 Tag baz of compiler block2 End of compiler", $this->cytro->fetch('custom.tpl', array()));
}
}
diff --git a/tests/resources/actions.php b/tests/resources/actions.php
index 86bea40..e22887f 100644
--- a/tests/resources/actions.php
+++ b/tests/resources/actions.php
@@ -12,20 +12,20 @@ function myBlockFunc($params, $content) {
return "Block:".$params["name"].':'.trim($content).':Block';
}
-function myCompiler(Aspect\Tokenizer $tokenizer, Aspect\Template $tpl) {
+function myCompiler(Cytro\Tokenizer $tokenizer, Cytro\Template $tpl) {
$p = $tpl->parseParams($tokenizer);
return 'echo "PHP_VERSION: ".PHP_VERSION." (for ".'.$p["name"].'.")";';
}
-function myBlockCompilerOpen(Aspect\Tokenizer $tokenizer, Aspect\Scope $scope) {
+function myBlockCompilerOpen(Cytro\Tokenizer $tokenizer, Cytro\Scope $scope) {
return myCompiler($tokenizer, $scope->tpl);
}
-function myBlockCompilerClose(Aspect\Tokenizer $tokenizer, Aspect\Scope $scope) {
+function myBlockCompilerClose(Cytro\Tokenizer $tokenizer, Cytro\Scope $scope) {
return 'echo "End of compiler";';
}
-function myBlockCompilerTag(Aspect\Tokenizer $tokenizer, Aspect\Scope $scope) {
+function myBlockCompilerTag(Cytro\Tokenizer $tokenizer, Cytro\Scope $scope) {
$p = $scope->tpl->parseParams($tokenizer);
return 'echo "Tag ".'.$p["name"].'." of compiler";';
}
\ No newline at end of file
diff --git a/tests/resources/provider/blocks.tpl b/tests/resources/provider/blocks.tpl
new file mode 100644
index 0000000..8faf8ac
--- /dev/null
+++ b/tests/resources/provider/blocks.tpl
@@ -0,0 +1,7 @@
+{block 'header'}
+ header block
+{/block}
+
+{block 'bottom'}
+ bottom block
+{/block}
\ No newline at end of file
diff --git a/tests/resources/provider/child.tpl b/tests/resources/provider/child.tpl
new file mode 100644
index 0000000..a230208
--- /dev/null
+++ b/tests/resources/provider/child.tpl
@@ -0,0 +1,6 @@
+{extends 'parent.tpl'}
+up
+{block 'header'}empty header{/block}
+middle
+{block 'bottom'}empty bottom{/block}
+down
diff --git a/tests/resources/provider/include.tpl b/tests/resources/provider/include.tpl
new file mode 100644
index 0000000..f166071
--- /dev/null
+++ b/tests/resources/provider/include.tpl
@@ -0,0 +1 @@
+include template
\ No newline at end of file
diff --git a/tests/resources/provider/macros.tpl b/tests/resources/provider/macros.tpl
new file mode 100644
index 0000000..009eada
--- /dev/null
+++ b/tests/resources/provider/macros.tpl
@@ -0,0 +1,7 @@
+{macro add(a, b)}
+ a + b = {$a + $b}
+{/macro}
+
+{macro rem(a, b)}
+ a - b = {$a - $b}
+{/macro}
\ No newline at end of file
diff --git a/tests/resources/provider/parent.tpl b/tests/resources/provider/parent.tpl
new file mode 100644
index 0000000..85599d3
--- /dev/null
+++ b/tests/resources/provider/parent.tpl
@@ -0,0 +1,2 @@
+{block 'header'}header body{/block}
+{block 'bottom'}bottom body{/block}
\ No newline at end of file