diff options
author | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-17 23:42:10 -0500 |
---|---|---|
committer | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-17 23:42:10 -0500 |
commit | 1df7761e1aed7b3551ea107a5f932cac8c23c66f (patch) | |
tree | e9e99f8851a8372f2a5517a7de74c005b831191b /php/template-test.php | |
parent | c642b44cdd615e021db81d98629afa7a5bd68050 (diff) | |
download | luigi-template-1df7761e1aed7b3551ea107a5f932cac8c23c66f.tar.bz2 luigi-template-1df7761e1aed7b3551ea107a5f932cac8c23c66f.zip |
add php
Diffstat (limited to 'php/template-test.php')
-rw-r--r-- | php/template-test.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/php/template-test.php b/php/template-test.php new file mode 100644 index 0000000..e7d5587 --- /dev/null +++ b/php/template-test.php @@ -0,0 +1,64 @@ +<?php + +error_reporting(E_ALL | E_STRICT); + +require 'template.php'; + +# build template string +$template_str = join("\n", array( + # test basic templates + "%{greet}, %{name}!", + + # test filters and filters with parameters + "Your name hashes to: %{ + name + | + hash + sha1 + | + uc + }", + + # test custom filter + "Your custom filtered name is: %{name|custom}", + + # test custom filter with arguments + "Your custom_args name is: %{name|custom_args foo bar baz}", + + # test whitespace in filters + "random test: %{name | hash sha512 | base64| uc }", + + # test pluralize filter + 'pluralize test (0): %{count_0} item%{count_0 | s}', + 'pluralize test (1): %{count_1} item%{count_1 | s}', + 'pluralize test (10): %{count_10} item%{count_10 | s}', +)) . "\n"; + +Luigi\Filters::add(array( + 'custom' => function() { + return 'custom'; + }, + + 'custom_args' => function($v, $args) { + return join(',', array_map(function($arg) use ($v) { + return "$arg$v"; + }, $args)); + }, +)); + +# build template +$t = new Luigi\Template($template_str); + +$args = array( + 'greet' => 'hello', + 'name' => 'paul', + 'count_0' => 0, + 'count_1' => 1, + 'count_10' => 10, +); + +# print results +echo $t->run($args); + +# test static invocation +echo Luigi\Template::run_once($template_str, $args); |