/** * constructor, set to private for only singleton instance allowed * * @param array $tplConfig * @throws TemplateException */ private function __construct(array $tplConfig = array()) { $this->_tplConfig = simphp_array_merge($this->_tplConfig, $tplConfig); if ('PlainTpl' === $this->driverClass) { $this->driverEntry = '/core/libs/plaintpl/PlainTpl.class.php'; } //...other template engine $driverFile = SIMPHP_ROOT . $this->driverEntry; if (!file_exists($driverFile)) { throw new TemplateException("Template Driver Entry File '{$driverFile}' Not Found."); } include $driverFile; if (!SimPHP::isClassLoaded($this->driverClass)) { throw new TemplateClassNotFoundException($this->driverClass); } // Create and Configure Template Driver Class $this->driverObj = new $this->driverClass(); if ($this->driverConfig) { foreach ($this->driverConfig as $key => $val) { $this->driverObj->{$key} = $val; } } // Register Template Functions $this->register_functions(); // Regsiter Template Blocks $this->register_blocks(); }
/** * merge array recursively, like array_merge_recursive(), it will merge recursively; * But and like array_merge(), the later one will overcome the previous one * @return Ambigous <mixed, unknown> */ function simphp_array_merge() { $arrays = func_get_args(); $base = array_shift($arrays); foreach ($arrays as $array) { reset($base); //important while (list($key, $value) = @each($array)) { if (is_array($value) && @is_array($base[$key])) { $base[$key] = simphp_array_merge($base[$key], $value); } else { $base[$key] = $value; } } } return $base; }