* @license PHP License * @package Wombat * @subpackage base */ /** * Instance creator * * Functor to encapsulate new operator * * @version 0.3.1 * @package Wombat * @subpackage base */ class WBClass_Creator_patTemplate extends WBClass_Creator { /** * tells whether this object is the first created * @return bool */ static private $first = true; /** * template engine * @var patTemplate */ private $tmpl; /** * return new object * * @return object */ public function instantiate( $parameter = array() ) { if (self::$first) { WBClass::load('WBErrorHandler_Pat'); /* * PATTEMPLATE_READER_NOTICE_TEMPLATE_EXISTS = 6051 * Unfortunately this constant is not defined yet :-( */ patErrorManager::addIgnore(6051); self::$first = false; } $baseDir = WBParam::get('wb/dir/base'); $sysDir = WBParam::get('wb/dir/system'); $this->tmpl = new patTemplate(); $this->tmpl->setRoot($baseDir . '/template'); // configure module dirs $incDirs = array($baseDir); if ($baseDir != $sysDir) { $incDirs[] = $sysDir; } foreach ($incDirs as $incDir) { $moduleDir = $incDir . '/include/patEx/Template'; $this->tmpl->addModuleDir('Function', $moduleDir . '/Function'); $this->tmpl->addModuleDir('Modifier', $moduleDir . '/Modifier'); //$this->tmpl->addModuleDir('TemplateCache', $moduleDir . '/TemplateCache'); } if (WBParam::get('wb/html/compress', 'minimize') == 'minimize') { $this->tmpl->setDefaultAttribute('whitespace', 'trim'); } // add locale settings $lang = array( 'short' => 'en', 'lang' => 'en', 'complete' => 'en' ); if (class_exists('patI18n', false)) { $lang['short'] = patI18n::getLocale(patI18n::LOCALE_TYPE_SHORT); $lang['lang'] = patI18n::getLocale(patI18n::LOCALE_TYPE_LANG); $lang['complete'] = patI18n::getLocale(patI18n::LOCALE_TYPE_COMPLETE); } $this->tmpl->addGlobalVars($lang, 'LOCALE_LANG_'); $this->startCache($lang); return $this->tmpl; } /** * Start template cache * * Use caching facility locale aware * * @todo implement this properly * @param $lang */ private function startCache($lang) { if (!WBParam::get('wb/cache/use', 0)) { return; } $cacheDir = WBParam::get('wb/dir/base') . '/var/cache/template'; if (!is_dir($cacheDir)) { mkdir($cacheDir); chmod($cacheDir, 0777); } $params = array( 'prefix' => $lang['lang'] . '-', 'cacheFolder' => $cacheDir, 'filemode' => 0666 ); $this->tmpl->useTemplateCache('File', $params); } } ?>