Beispiel #1
0
 public function render($templateName)
 {
     $path = $this->templateDirectory . '/' . $templateName . $this->templatePrefix;
     if (!file_exists($path)) {
         throw new RuntimeException('file not found: ' . $path);
     }
     $tpl = $this->getContents($path);
     $tpl = mb_convert_encoding($tpl, 'HTML-ENTITIES', 'auto');
     $document = new DOMDocument();
     // dtd の検証を行う
     $document->validateOnParse = false;
     // 余分なwhitespaceを取り除く
     $document->preserveWhiteSpace = false;
     // 整形した出力
     //$document->formatOutput = true;
     $document->loadXML($tpl);
     $repository = $this->getTagRepository();
     $context = $this->context;
     $context->setGlobalAttibute('document', $document);
     $handler = new ChariotRootTagHandler();
     $handler->start($context, $repository);
     return $document->saveHTML();
 }
Beispiel #2
0
                break;
            }
        }
        return $variable;
    }
}
$start = microtime(true);
$tpl = file_get_contents('foreach.tpl');
$tpl = file_get_contents('foreach_index.tpl');
$tpl = file_get_contents('foreach_dummy.tpl');
$tpl = file_get_contents('exists.tpl');
$tpl = mb_convert_encoding($tpl, 'HTML-ENTITIES', 'auto');
$document = new DOMDocument();
$document->validateOnParse = false;
$document->preserveWhiteSpace = false;
$document->loadXML($tpl);
$repository = new ChariotTagRepository();
$repository->set('exists', new ChariotExistsTagHandler());
$repository->set('foreach', new ChariotForeachTagHandler());
$repository->set('symfony', new ChariotSymfonyTagHandler());
$repository->set('context', new ChariotContextTagHandler());
$context = new ChariotContext();
$context->setGlobalAttibute('document', $document);
$context->setAttribute('Hoge', array(array('name' => 'hello', 'entry' => 'world'), array('name' => 'hello2', 'entry' => 'world2')));
$context->setAttribute('Foo', array('aaa' => array('name' => 'foo_name_1', 'value' => 'foo_value_1'), 'bbb' => array('name' => 'foo_name_2', 'value' => 'foo_value_2'), 'ccc' => array('name' => 'foo_name_3', 'value' => 'foo_value_3'), '1' => array('name' => 'foo_name_4', 'value' => 'foo_value_4'), '2' => array('name' => 'foo_name_5', 'value' => 'foo_value_5'), '3' => array('name' => 'foo_name_6', 'value' => 'foo_value_6')));
$context->setAttribute('Bar', array('value' => 'bar_value'));
$context->setAttribute('Baz', array(1, 2, 3, 4, 5, 6, 7));
$root = new ChariotRootTagHandler();
$root->start($context, $repository);
var_dump($document->saveHTML());
echo 'elapsed time: ', microtime(true) - $start, ' ms', PHP_EOL;