function __construct($file = '', $options = array()) { # Init a environment $this->options = $this->getOptions($options); $loader = $this->options['loader']; if (!$loader) { return true; } if (is_object($loader)) { $this->loader = $loader; $this->loader->setOptions($this->options); } else { $loaderClass = "H2o_{$loader}_Loader"; if (!class_exists($loaderClass)) { throw new Exception('Invalid template loader'); } if (isset($options['searchpath'])) { $this->searchpath = realpath($options['searchpath']) . DS; } else { $this->searchpath = dirname(realpath($file)) . DS; } $this->loader = new $loaderClass($this->searchpath, $this->options); } if (isset($options['i18n'])) { $i18n_options = array(); if (is_array($options['i18n'])) { $i18n_options = $options['i18n']; } h2o::load('i18n'); $this->i18n = new H2o_I18n($this->searchpath, $i18n_options); } $this->loader->runtime = $this; $this->nodelist = $this->loadTemplate($file); }
function __construct($file = null, $options = array()) { # Init a environment $this->options = $this->getOptions($options); $loader = $this->options['loader']; if (!$loader) { return true; } if (is_object($loader)) { $this->loader = $loader; $this->loader->setOptions($this->options); } else { $loader = __NAMESPACE__ . '\\' . "H2o_{$loader}_Loader"; if (!class_exists($loader)) { throw new \Exception('Invalid template loader'); } if (isset($options['searchpath'])) { $this->searchpath = realpath($options['searchpath']) . DS; } elseif ($file) { $this->searchpath = dirname(realpath($file)) . DS; } else { $this->searchpath = getcwd() . DS; } $this->loader = new $loader($this->searchpath, $this->options); } $this->loader->runtime = $this; if (isset($options['i18n'])) { h2o::load('i18n'); $this->i18n = new H2o_I18n($this->searchpath, $options['i18n']); } if ($file) { $this->nodelist = $this->loadTemplate($file); } }
private function load() { if (isset(h2o::$extensions[$this->extension])) { return true; } foreach ($this->searchpath as $path) { $file = $path . 'ext' . DS . $this->extension . '.php'; if (is_file($file)) { h2o::load($this->extension, $file); return $file; } } throw new H2o_Error("Extension: {$this->extension} cannot be loaded, please confirm it exist in extension path"); }
<?php print_r(memory_get_usage()); include '../h2o.php'; h2o::load('i18n'); //// Set language to German //$i18n = new H2o_I18n(dirname(__FILE__).DS, array( // 'gettext_path' => dirname(__FILE__).DS.'bin/gettext/bin/' //)); //$i18n->setLocale('fr'); // //$i18n->extract(); //$i18n->compile(); //// // Choose domain //extract_translations( // realpath('trans.tpl'), array('tpl', 'html'), dirname(__FILE__).DS.'bin/gettext/bin/' //); // //compile_translations( // realpath('trans.tpl'), null, dirname(__FILE__).DS.'bin/gettext/bin/' //); $template = new H2o('trans.tpl', array('cache' => false, 'cache_dir' => dirname(__FILE__))); $time_start = microtime(true); for ($i = 0; $i < 10; $i++) { $r = $template->render(array('users' => array(array('username' => 'peter', 'tasks' => array('school', 'writing'), 'user_id' => 1), array('username' => 'anton', 'tasks' => array('go shopping'), 'user_id' => 2), array('username' => 'john doe', 'tasks' => array('write report', 'call tony', 'meeting with arron'), 'user_id' => 3), array('username' => 'foobar', 'tasks' => array(), 'user_id' => 4)))); } echo $r; echo "in " . (microtime(true) - $time_start) . " seconds\n<br/>";