Changeset 1511
- Timestamp:
- 04/06/08 17:10:05 (1 month ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElement.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisTemplate.php (modified) (11 diffs)
- trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElementTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorCachableTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestHelper.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElement.php
r1502 r1511 8 8 */ 9 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubFileNotFoundException', 10 'net::stubbles::lang::exceptions::stubRuntimeException', 11 'net::stubbles::util::stubRegistry', 10 12 'net::stubbles::websites::memphis::stubMemphisPageElement', 11 13 'net::stubbles::websites::memphis::stubMemphisTemplate' trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php
r1459 r1511 17 17 'net::stubbles::websites::processors::stubPageBasedProcessor', 18 18 'net::stubbles::websites::memphis::stubMemphisConfig', 19 'net::stubbles::websites::memphis::stubMemphis Template'19 'net::stubbles::websites::memphis::stubMemphisPatTemplate' 20 20 ); 21 21 /** … … 223 223 protected function createTemplate() 224 224 { 225 $template = new stubMemphis Template(stubRegistry::getConfig(stubMemphisTemplate::REGISTRY_KEY_DIR, stubConfig::getPagePath() . '/../templates'));225 $template = new stubMemphisPatTemplate(stubRegistry::getConfig(stubMemphisTemplate::REGISTRY_KEY_DIR, stubConfig::getPagePath() . '/../templates')); 226 226 if (stubMode::$CURRENT->isCacheEnabled() === true) { 227 227 $template->enableCache(); 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 ?> trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisIncludeTemplatePageElementTestCase.php
r1502 r1511 112 112 public function process() 113 113 { 114 $mockMemphisTemplate = $this->getMock('stubMemphisTemplate' , array(), array(TEST_SRC_PATH));114 $mockMemphisTemplate = $this->getMock('stubMemphisTemplate'); 115 115 $this->includeTemplatePageElement->init($this->getMock('stubRequest'), $this->getMock('stubSession'), $this->getMock('stubResponse'), array('template' => $mockMemphisTemplate)); 116 116 $this->assertEquals('', $this->includeTemplatePageElement->process()); trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorCachableTestCase.php
r1459 r1511 81 81 $this->mockMemphisConfig = $this->getMock('TeststubMemphisConfig'); 82 82 $this->memphisProcessor->setConfig($this->mockMemphisConfig); 83 $this->mockMemphisTemplate = $this->getMock(' TeststubMemphisTemplate', array(), array(''));83 $this->mockMemphisTemplate = $this->getMock('stubMemphisTemplate'); 84 84 $this->memphisProcessor->setTemplate($this->mockMemphisTemplate); 85 85 $this->mockPage = $this->getMock('stubPage'); trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php
r1459 r1511 150 150 $this->mockMemphisConfig = $this->getMock('TeststubMemphisConfig'); 151 151 $this->memphisProcessor->setConfig($this->mockMemphisConfig); 152 $this->mockMemphisTemplate = $this->getMock(' TeststubMemphisTemplate', array(), array(''));152 $this->mockMemphisTemplate = $this->getMock('stubMemphisTemplate'); 153 153 $this->memphisProcessor->setTemplate($this->mockMemphisTemplate); 154 154 $this->mockPage = $this->getMock('stubPage'); … … 188 188 $mockPageElement2->expects($this->any())->method('isAvailable')->will($this->returnValue(true)); 189 189 $mockPageElement2->expects($this->exactly(2))->method('process')->will($this->returnValue('Mock2')); 190 $this->mockMemphisTemplate->expectAt(0, 'addGlobalVar', array('content', 'defaultMock2Mock2')); 191 $this->mockMemphisTemplate->expectAt(1, 'addGlobalVar', array('teaser', 'defaultMock2Mock2')); 190 $this->mockMemphisTemplate->expects($this->at(1)) 191 ->method('addGlobalVar') 192 ->with($this->equalTo('content'), $this->equalTo('defaultMock2Mock2')); 193 $this->mockMemphisTemplate->expects($this->at(2)) 194 ->method('addGlobalVar') 195 ->with($this->equalTo('teaser'), $this->equalTo('defaultMock2Mock2')); 192 196 $this->mockMemphisTemplate->expects($this->once())->method('getParsedTemplate')->will($this->returnValue('defaultMock2Mock2defaultMock2Mock2')); 193 197 $this->mockResponse->expects($this->once())->method('write')->with($this->equalTo('defaultMock2Mock2defaultMock2Mock2')); trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestHelper.php
r1459 r1511 19 19 */ 20 20 public function __construct() { } 21 }22 /**23 * Extends the original class to get rid of patTemplate dependency.24 *25 * @package stubbles26 * @subpackage websites_memphis_test27 */28 class TeststubMemphisTemplate extends stubMemphisTemplate29 {30 /**31 * constructor32 *33 * @param string $baseDir directory where template files can be found34 * @param array $namespaces optional namespaces for patTemplate tags, default patTemplate35 * @param array $options optional configuration options for patTemplate36 */37 public function __construct($baseDir, array $namespaces = array(), array $options = array()) { }38 21 } 39 22 /**
