Changeset 22543
- Timestamp:
- 09/28/09 14:14:10 (4 years ago)
- Files:
-
- components/templating/trunk/doc/04-Template-Loaders.markdown (modified) (3 diffs)
- components/templating/trunk/doc/05-Template-Renderers.markdown (modified) (8 diffs)
- components/templating/trunk/lib/sfTemplateEngine.php (modified) (1 diff)
- components/templating/trunk/lib/sfTemplateLoaderCache.php (modified) (1 diff)
- components/templating/trunk/lib/sfTemplateLoaderChain.php (modified) (2 diffs)
- components/templating/trunk/lib/sfTemplateLoaderFilesystem.php (modified) (1 diff)
- components/templating/trunk/lib/sfTemplateLoaderInterface.php (modified) (1 diff)
- components/templating/trunk/lib/sfTemplateRendererInterface.php (modified) (1 diff)
- components/templating/trunk/lib/sfTemplateRendererPhp.php (modified) (2 diffs)
- components/templating/trunk/lib/sfTemplateStorage.php (modified) (1 diff)
- components/templating/trunk/test/unit/sfTemplateEngineTest.php (modified) (4 diffs)
- components/templating/trunk/test/unit/sfTemplateRendererPhpTest.php (modified) (2 diffs)
- components/templating/trunk/test/unit/sfTemplateRendererTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
components/templating/trunk/doc/04-Template-Loaders.markdown
r22215 r22543 140 140 >abstract base class, which provides a debugger interface. 141 141 142 The ~`load()`~ method must return one of the following: 143 144 * A string representing the template; 145 146 * A `sfTemplateStorage` instance. 142 The ~`load()`~ method must return a `sfTemplateStorage` instance. 147 143 148 144 ### Template ~Storages|storage~ … … 185 181 } 186 182 187 return $rows[0][0];183 return new sfTemplateStorageString($rows[0][0]); 188 184 } 189 185 } … … 233 229 if (method_exists($this, $method = 'getTemplate'.$template)) 234 230 { 235 return $this->$method();231 return new sfTemplateStorageString($this->$method()); 236 232 } 237 233 components/templating/trunk/doc/05-Template-Renderers.markdown
r22215 r22543 43 43 interface sfTemplateEngineInterface 44 44 { 45 function evaluate( $template, array $parameters = array());45 function evaluate(sfTemplateStorage $template, array $parameters = array()); 46 46 47 47 function setEngine(sfTemplateEngine $engine); … … 53 53 >automatically call the engine methods. 54 54 55 The `$template` variable can be any of the following: 56 57 * A string representing the template; 58 59 * A `sfTemplateStorage` instance. 55 The `$template` must be a `sfTemplateStorage` instance. 60 56 61 57 >**NOTE** … … 68 64 69 65 [php] 70 public function evaluate( $template, array $parameters = array())66 public function evaluate(sfTemplateStorage $template, array $parameters = array()) 71 67 { 72 68 if ($template instanceof sfTemplateStorageFile) … … 78 74 return ob_get_clean(); 79 75 } 80 else if (is_string($template) ||$template instanceof sfTemplateStorageString)76 elseif ($template instanceof sfTemplateStorageString) 81 77 { 82 78 extract($parameters); … … 106 102 class ProjectTemplateRenderer extends sfTemplateRenderer 107 103 { 108 public function evaluate( $template, array $parameters = array())104 public function evaluate(sfTemplateStorage $template, array $parameters = array()) 109 105 { 110 106 if ($template instanceof sfTemplateStorageFile) … … 126 122 In the `evaluate()` method, we get the content of the template on the 127 123 filesystem if the template is an instance of `sfTemplateStorageFile`. If not, 128 the template is a string or an object with a `__toString()` method. 124 the template is an object with a `__toString()` method that returns the 125 content of the template. 129 126 130 127 >**NOTE** … … 151 148 } 152 149 153 public function evaluate( $template, array $parameters = array())150 public function evaluate(sfTemplateStorage $template, array $parameters = array()) 154 151 { 155 152 if ($template instanceof sfTemplateStorageFile) … … 157 154 $this->tal->setTemplate((string) $template); 158 155 } 159 else if (is_string($template) ||$template instanceof sfTemplateStorageString)156 elseif ($template instanceof sfTemplateStorageString) 160 157 { 161 158 $this->tal->setSource((string) $template); components/templating/trunk/lib/sfTemplateEngine.php
r22215 r22543 92 92 93 93 // renderer 94 if ($template instanceof sfTemplateStorage && $template->getRenderer())94 if ($template->getRenderer()) 95 95 { 96 96 $renderer = $template->getRenderer(); components/templating/trunk/lib/sfTemplateLoaderCache.php
r22215 r22543 46 46 * @param string $renderer The renderer to use 47 47 * 48 * @return s tring|Boolean false if the template cannot be loaded, the loaded template otherwise48 * @return sfTemplateStorage|Boolean false if the template cannot be loaded, a sfTemplateStorage instance otherwise 49 49 */ 50 50 public function load($template, $renderer = 'php') components/templating/trunk/lib/sfTemplateLoaderChain.php
r22215 r22543 52 52 * @param string $renderer The renderer to use 53 53 * 54 * @return s tring|Boolean false if the template cannot be loaded, the loaded template otherwise54 * @return sfTemplateStorage|Boolean false if the template cannot be loaded, a sfTemplateStorage instance otherwise 55 55 */ 56 56 public function load($template, $renderer = 'php') … … 58 58 foreach ($this->loaders as $loader) 59 59 { 60 if (false !== $ content = $loader->load($template, $renderer))60 if (false !== $ret = $loader->load($template, $renderer)) 61 61 { 62 return $ content;62 return $ret; 63 63 } 64 64 } components/templating/trunk/lib/sfTemplateLoaderFilesystem.php
r22215 r22543 44 44 * @param string $renderer The renderer to use 45 45 * 46 * @return s tring|Boolean false if the template cannot be loaded, the loaded template otherwise46 * @return sfTemplateStorage|Boolean false if the template cannot be loaded, a sfTemplateStorage instance otherwise 47 47 */ 48 48 public function load($template, $renderer = 'php') components/templating/trunk/lib/sfTemplateLoaderInterface.php
r22215 r22543 26 26 * @param string $renderer The renderer to use 27 27 * 28 * @return s tring|Boolean false if the template cannot be loaded, the loaded template otherwise28 * @return sfTemplateStorage|Boolean false if the template cannot be loaded, a sfTemplateStorage instance otherwise 29 29 */ 30 30 function load($template, $renderer = 'php'); components/templating/trunk/lib/sfTemplateRendererInterface.php
r22215 r22543 23 23 * Evaluates a template. 24 24 * 25 * @param mixed$template The template to render26 * @param array $parameters An array of parameters to pass to the template25 * @param sfTemplateStorage $template The template to render 26 * @param array $parameters An array of parameters to pass to the template 27 27 * 28 28 * @return string|false The evaluated template, or false if the renderer is unable to render the template 29 29 */ 30 function evaluate( $template, array $parameters = array());30 function evaluate(sfTemplateStorage $template, array $parameters = array()); 31 31 32 32 /** components/templating/trunk/lib/sfTemplateRendererPhp.php
r22215 r22543 23 23 * Evaluates a template. 24 24 * 25 * @param mixed$template The template to render26 * @param array $parameters An array of parameters to pass to the template25 * @param sfTemplateStorage $template The template to render 26 * @param array $parameters An array of parameters to pass to the template 27 27 * 28 28 * @return string|false The evaluated template, or false if the renderer is unable to render the template 29 29 */ 30 public function evaluate( $template, array $parameters = array())30 public function evaluate(sfTemplateStorage $template, array $parameters = array()) 31 31 { 32 32 if ($template instanceof sfTemplateStorageFile) … … 38 38 return ob_get_clean(); 39 39 } 40 else if ( is_string($template) ||$template instanceof sfTemplateStorageString)40 else if ($template instanceof sfTemplateStorageString) 41 41 { 42 42 extract($parameters); components/templating/trunk/lib/sfTemplateStorage.php
r22215 r22543 42 42 public function __toString() 43 43 { 44 return $this->template;44 return (string) $this->template; 45 45 } 46 46 components/templating/trunk/test/unit/sfTemplateEngineTest.php
r22215 r22543 15 15 require_once dirname(__FILE__).'/lib/SimpleHelper.php'; 16 16 17 $t = new lime_test(3 5);17 $t = new lime_test(33); 18 18 19 19 class ProjectTemplateEngine extends sfTemplateEngine … … 51 51 if (isset($this->templates[$template.'.'.$renderer])) 52 52 { 53 return $this->templates[$template.'.'.$renderer];53 return new sfTemplateStorageString($this->templates[$template.'.'.$renderer]); 54 54 } 55 55 … … 192 192 $t->is($engine->render('foo', array('foo' => 'foo', 'bar' => 'bar')), 'bar-foo-', '->render() supports render() calls in templates'); 193 193 194 $loader->setTemplate('foobar.php', new stdClass());195 try196 {197 $engine->render('foobar');198 $t->fail('->render() throws a RuntimeException if the template cannot be rendered');199 }200 catch (RuntimeException $e)201 {202 $t->pass('->render() throws a RuntimeException if the template cannot be rendered');203 }204 205 $loader->setTemplate('foobarbar.php', '<?php echo $this->extend("foobar") ?>');206 try207 {208 $engine->render('foobarbar');209 $t->fail('->render() throws a RuntimeException if the template cannot be rendered');210 }211 catch (RuntimeException $e)212 {213 $t->pass('->render() throws a RuntimeException if the template cannot be rendered');214 }215 216 194 class CompilableTemplateLoader extends sfTemplateLoader implements sfTemplateLoaderCompilableInterface 217 195 { … … 229 207 class FooTemplateRenderer extends sfTemplateRenderer 230 208 { 231 public function evaluate( $template, array $parameters = array())209 public function evaluate(sfTemplateStorage $template, array $parameters = array()) 232 210 { 233 211 return 'foo'; components/templating/trunk/test/unit/sfTemplateRendererPhpTest.php
r22215 r22543 14 14 sfTemplateAutoloader::register(); 15 15 16 $t = new lime_test( 4);16 $t = new lime_test(2); 17 17 18 18 $renderer = new sfTemplateRendererPhp(); … … 20 20 // ->evaluate() 21 21 $t->diag('->evaluate()'); 22 $t->ok(false === $renderer->evaluate(new stdClass()), '->evaluate() returns false if it is not able to render the template');23 22 24 23 $template = new sfTemplateStorageString('<?php echo $foo ?>'); 25 24 $t->is($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are instances of sfTemplateStorageString'); 26 25 27 $template = '<?php echo $foo ?>';28 $t->is($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are simple strings');29 30 26 $template = new sfTemplateStorageFile(dirname(__FILE__).'/fixtures/templates/foo.php'); 31 27 $t->is($renderer->evaluate($template, array('foo' => 'bar')), 'bar', '->evaluate() renders templates that are instances of sfTemplateStorageFile'); components/templating/trunk/test/unit/sfTemplateRendererTest.php
r22215 r22543 24 24 } 25 25 26 public function evaluate( $template, array $parameters = array())26 public function evaluate(sfTemplateStorage $template, array $parameters = array()) 27 27 { 28 28 }