- Timestamp:
- 04/06/08 17:10:05 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisTemplate.php
r1466 r1511 1 1 <?php 2 2 /** 3 * Proxy for patTemplate.3 * Interface for template implementations. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 7 7 * @subpackage websites_memphis 8 8 */ 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalAccessException',10 'net::stubbles::util::stubRegistry'11 );12 9 /** 13 * Proxy for patTemplate.10 * Interface for template implementations. 14 11 * 15 12 * @author Frank Kleine <mikey@stubbles.net> … … 17 14 * @subpackage websites_memphis 18 15 */ 19 // @codeCoverageIgnoreStart 20 class stubMemphisTemplate extends stubBaseObject 16 interface stubMemphisTemplate extends stubObject 21 17 { 22 18 /** 23 19 * registry key for template dir setting 24 20 */ 25 const REGISTRY_KEY_DIR = 'net.stubbles.websites.memphis.templateDir'; 26 /** 27 * the patTemplate instance 28 * 29 * @var patTemplate 30 */ 31 protected $template; 32 /** 33 * switch whether template classes are already initialized or not 34 * 35 * @var bool 36 */ 37 protected static $initialized = false; 21 const REGISTRY_KEY_DIR = 'net.stubbles.websites.memphis.templateDir'; 38 22 39 23 /** … … 44 28 * @param array $options optional configuration options for patTemplate 45 29 */ 46 public function __construct($baseDir, array $namespaces = array(), array $options = array()) 47 { 48 if (false === self::$initialized) { 49 // do not use __static() because we want to load the code only when 50 // it is really required 51 stubClassLoader::load('net::stubbles::util::ext::stubPhpToolsClassLoader'); 52 $patClassLoader = new stubPhpToolsClassLoader(stubRegistry::getConfig('net.php-tools.path', stubConfig::getLibPath() . '/pat')); 53 stubClassLoader::registerForeignClassLoader($patClassLoader); 54 stubClassLoader::load('net::php-tools::patErrorManager'); 55 stubClassLoader::load('net::php-tools::patTemplate'); 56 self::$initialized = true; 57 } 58 59 if (count($namespaces) === 0) { 60 $namespaces = array('patTemplate'); 61 } 62 63 if (isset($options['componentExtension']) === false) { 64 $options['componentExtension'] = '.tmpl'; 65 } 66 67 $this->template = new patTemplate(); 68 $this->template->setBasedir($baseDir); 69 $this->template->setNamespace($namespaces); 70 foreach ($options as $optionName => $optionValue) { 71 $this->template->setOption($optionName, $optionValue); 72 } 73 } 30 #public function __construct($baseDir, array $namespaces = array(), array $options = array()); 74 31 75 32 /** … … 84 41 * @param string $type optional patTemplate cache driver 85 42 */ 86 public function enableCache($cacheDir = null, $prefix = 'tmpl_', $type = 'File') 87 { 88 if (null == $cacheDir) { 89 $cacheDir = stubConfig::getCachePath() . '/patTemplate'; 90 } 91 92 $this->template->useTemplateCache($type, array('cacheFolder' => $cacheDir, 93 'prefix' => $prefix 94 ) 95 ); 96 } 43 public function enableCache($cacheDir = null, $prefix = 'tmpl_', $type = 'File'); 97 44 98 45 /** … … 106 53 * @throws stubException 107 54 */ 108 public function readTemplatesFromInput($input, $reader = 'File', array $options = null, $parseInto = null) 109 { 110 $return = $this->template->readTemplatesFromInput($input, $reader, $options, $parseInto); 111 if (patErrorManager::isError($return) === true) { 112 throw new stubException($return->getMessage()); 113 } 114 115 return $return; 116 } 55 public function readTemplatesFromInput($input, $reader = 'File', array $options = null, $parseInto = null); 117 56 118 57 /** … … 126 65 * @return bool 127 66 */ 128 public function addVar($template, $varname, $value) 129 { 130 return $this->template->addVar($template, $varname, $value); 131 } 132 67 public function addVar($template, $varname, $value); 133 68 /** 134 69 * adds several variables to a template … … 142 77 * @return bool 143 78 */ 144 public function addVars($template, $variables, $prefix = '') 145 { 146 return $this->template->addVars($template, $variables, $prefix); 147 } 79 public function addVars($template, $variables, $prefix = ''); 148 80 149 81 /** … … 157 89 * @return bool 158 90 */ 159 public function addGlobalVar($varname, $value) 160 { 161 return $this->template->addGlobalVar($varname, $value); 162 } 91 public function addGlobalVar($varname, $value); 163 92 164 93 /** … … 173 102 * @return bool 174 103 */ 175 public function addGlobalVars($variables, $prefix = '') 176 { 177 return $this->template->addGlobalVars($variables, $prefix); 178 } 104 public function addGlobalVars($variables, $prefix = ''); 179 105 180 106 /** … … 189 115 * @throws stubException 190 116 */ 191 public function getParsedTemplate($name = null, $applyFilters = false) 192 { 193 $return = $this->template->getParsedTemplate($name, $applyFilters); 194 if (patErrorManager::isError($return) === true) { 195 throw new stubException($return->getMessage()); 196 } 197 198 return $return; 199 } 200 201 /** 202 * redirects all calls to the instance of patTemplate 203 * 204 * @param string $method name of method to call 205 * @param array $arguments arguments to call method with 206 * @return mixed 207 * @throws stubIllegalAccessException 208 * @throws stubException 209 */ 210 public function __call($method, $arguments) 211 { 212 if (method_exists($this->template, $method) === true) { 213 $return = call_user_func_array(array($this->template, $method), $arguments); 214 if (patErrorManager::isError($return) === true) { 215 throw new stubException($return->getMessage()); 216 } 217 218 return $return; 219 } 220 221 $backtrace = debug_backtrace(); 222 throw new stubIllegalAccessException('Method patTemplate::' . $method . ' called in ' . $backtrace[2]['class'] . '::' . $backtrace[2]['function'] . '() on line ' . $backtrace[2]['line'] . ' does not exist.'); 223 } 117 public function getParsedTemplate($name = null, $applyFilters = false); 224 118 } 225 // @codeCoverageIgnoreEnd226 119 ?>
