* @license PHP License * @package Wombat * @subpackage base */ /** * Instance creator * * Functor to encapsulate new operator * * @version 0.5.0 * @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; } $this->tmpl = new patTemplate(); $this->tmpl->setOption('reader', 'Wombat'); $this->tmpl->setRoot('template'); // configure module dirs $incDirs = WBParam::get('wb/class/includePath'); foreach ($incDirs as $incDir) { $moduleDir = realpath($incDir . '/patEx/Template'); if (empty($moduleDir)) { continue; } $this->tmpl->addModuleDir('Reader', $moduleDir . '/Reader'); $this->tmpl->addModuleDir('Function', $moduleDir . '/Function'); $this->tmpl->addModuleDir('Modifier', $moduleDir . '/Modifier'); $this->tmpl->addModuleDir('Stat', $moduleDir . '/Stat'); $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(); return $this->tmpl; } /** * Start Template Cache * @param $lang */ private function startCache() { $cacheDir = WBParam::get('wb/dir/base') . '/var/cache/template'; if (!is_dir($cacheDir)) { mkdir($cacheDir); chmod($cacheDir, 0777); } $params = array( 'cacheFolder' => $cacheDir, 'filemode' => 0666 ); $this->tmpl->useTemplateCache('Wombat', $params); } }