Ejemplo n.º 1
0
 function __construct($template_path, $cache_dir = '')
 {
     if (!$cache_dir && defined('LIMB_VAR_DIR')) {
         $cache_dir = LIMB_VAR_DIR . '/compiled/';
     }
     $config = new lmbWactTemplateConfig($cache_dir);
     $locator = lmbToolkit::instance()->getWactLocator();
     parent::__construct($template_path, $config, $locator);
 }
Ejemplo n.º 2
0
 function __construct($raw_path_or_class_name, $include_path = '')
 {
     $raw_path_or_class_name = $this->_parseConstants($raw_path_or_class_name);
     if ($include_path) {
         $this->include_path = $include_path;
     } elseif (WactTemplate::isFileReadable($raw_path_or_class_name . '.class.php')) {
         $this->include_path = $raw_path_or_class_name . '.class.php';
     }
     $this->class_name = end(explode('/', $raw_path_or_class_name));
 }
Ejemplo n.º 3
0
 function rewind()
 {
     $ns = $this->number_source->current();
     $Number = WactTemplate::getValue($ns, 'BaseNumber');
     if (!empty($Number)) {
         $this->iterator = new WactArrayIterator(array(array('Num' => $Number), array('Num' => $Number * $Number), array('Num' => $Number * $Number * $Number)));
     } else {
         $this->iterator = new WactArrayIterator(array());
     }
     $this->iterator->rewind();
 }
Ejemplo n.º 4
0
 function process($template)
 {
     $command = $this->_createCommand($template);
     if (!is_a($command, 'WactTemplateCommand')) {
         throw new WactException($this->command . '" must inherite from WactTemplateCommand class');
     }
     $method = WactTemplate::toStudlyCaps('do_' . $this->method_name, false);
     if (!method_exists($command, $method)) {
         throw new WactException('Template command "' . $this->command . '" does not support method: ' . $method);
     }
     return call_user_func_array(array($command, $method), $this->params);
 }
Ejemplo n.º 5
0
 protected function _createFetcher()
 {
     $class_path = new WactClassPath($this->fetcher_name, $this->include_path);
     $fetcher = $class_path->createObject();
     foreach ($this->params as $param => $value) {
         $method = WactTemplate::toStudlyCaps('set_' . $param, false);
         if (in_array($param, $this->reserved_params)) {
             $this->{$method}($value);
         } elseif (method_exists($fetcher, $method)) {
             $fetcher->{$method}($value);
         } else {
             throw new WactException('Fetcher "' . $this->fetcher_name . '" does not support method: ' . $method);
         }
     }
     return $fetcher;
 }
Ejemplo n.º 6
0
 /**
  * Set a named property in the form DataSource
  */
 function setValue($name, $value)
 {
     WactTemplate::setValue($this->datasource, $name, $value);
 }
Ejemplo n.º 7
0
 protected function _addParamsToDataset($dataset, $params)
 {
     foreach ($params as $param => $value) {
         $method = WactTemplate::toStudlyCaps('set_' . $param);
         $dataset->{$method}($value);
     }
 }
Ejemplo n.º 8
0
 function testEscapeAlreadyTranslatedEntityWithNonNumericIndex()
 {
     $this->assertEqual(WactTemplate::escape('ሴ'), 'ሴ');
 }
Ejemplo n.º 9
0
 public function readTemplateFile($file_name)
 {
     if (WactTemplate::isFileReadable($file_name)) {
         return file_get_contents($file_name, 1);
     }
 }
Ejemplo n.º 10
0
 function registerDataset($dataset)
 {
     $this->dataset = WactTemplate::castToIterator($dataset);
     $this->cached_count = null;
 }
Ejemplo n.º 11
0
 function registerDataset($dataset)
 {
     $this->dataset = WactTemplate::castToIterator($dataset);
 }
Ejemplo n.º 12
0
require_once 'limb/wact/src/WactDefaultTemplateConfig.class.php';
for ($i = 0; $i < 1000; $i++) {
    $j = $i;
}
$name = 'Bob';
$tpl = new lmbMacroTemplate('macro.phtml', array('cache_dir' => '/tmp/macro', 'forcecompile' => false, 'forcescan' => false, 'tpl_scan_dirs' => array(dirname(__FILE__) . '/tpl')));
$tpl->set('name', $name);
$mark = microtime(true);
$tpl->render();
echo "MACRO 1xrender: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $tpl->render();
}
echo "MACRO 1000xrender: " . (microtime(true) - $mark) . "\n";
$tpl = new WactTemplate('wact.html', new WactDefaultTemplateConfig(dirname(__FILE__) . '/settings/wact.ini'));
$tpl->set('name', $name);
$mark = microtime(true);
$tpl->capture();
echo "WACT 1xrender: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
for ($i = 0; $i < 1000; $i++) {
    $tpl->capture();
}
echo "WACT 1000xrender: " . (microtime(true) - $mark) . "\n";
$mark = microtime(true);
ob_start();
include dirname(__FILE__) . '/tpl/native.phtml';
ob_get_contents();
ob_end_clean();
echo "PHP 1xrender: " . (microtime(true) - $mark) . "\n";
Ejemplo n.º 13
0
<?php

if (!isset($argv[1])) {
    die("\nTemplate argument is required\n");
}
$file = $argv[1];
set_include_path(dirname(__FILE__) . '/../../../../');
define('WACT_CACHE_DIR', '/tmp/wact');
define('WACT_TPLS', dirname(__FILE__));
require_once 'limb/wact/common.inc.php';
require_once 'limb/wact/src/WactTemplate.class.php';
require_once 'limb/wact/src/WactDefaultTemplateConfig.class.php';
require_once dirname(__FILE__) . '/profile.inc.php';
$tpl = new WactTemplate($file, new WactDefaultTemplateConfig(dirname(__FILE__) . '/settings/wact.ini'));
for ($i = 2; $i < $argc; $i++) {
    list($key, $value) = explode('=', $argv[$i]);
    $tpl->set($key, $value);
}
profile_start();
for ($i = 0; $i < 1000; $i++) {
    $tpl->capture();
}
profile_end("running {$i} iterations of capture");
Ejemplo n.º 14
0
 function get($field)
 {
     return WactTemplate::getValue($this->datasource, $field);
 }