瀏覽代碼

[Templating] renamed the template object in templates to view instead of this

Fabien Potencier 15 年之前
父節點
當前提交
8ff8464420

+ 1 - 1
src/Symfony/Components/Templating/Engine.php

@@ -159,7 +159,7 @@ class Engine
    */
    */
   public function __get($name)
   public function __get($name)
   {
   {
-    return $this->helperSet->get($name);
+    return $this->$name = $this->helperSet->get($name);
   }
   }
 
 
   /**
   /**

+ 2 - 0
src/Symfony/Components/Templating/Renderer/PhpRenderer.php

@@ -37,6 +37,7 @@ class PhpRenderer extends Renderer
     if ($template instanceof FileStorage)
     if ($template instanceof FileStorage)
     {
     {
       extract($parameters);
       extract($parameters);
+      $view = $this->engine;
       ob_start();
       ob_start();
       require $template;
       require $template;
 
 
@@ -45,6 +46,7 @@ class PhpRenderer extends Renderer
     else if ($template instanceof StringStorage)
     else if ($template instanceof StringStorage)
     {
     {
       extract($parameters);
       extract($parameters);
+      $view = $this->engine;
       ob_start();
       ob_start();
       eval('; ?>'.$template.'<?php ;');
       eval('; ?>'.$template.'<?php ;');
 
 

+ 0 - 30
src/Symfony/Components/Templating/Renderer/Renderer.php

@@ -33,34 +33,4 @@ abstract class Renderer implements RendererInterface
   {
   {
     $this->engine = $engine;
     $this->engine = $engine;
   }
   }
-
-  /**
-   * Forwards the call to the associated template instance.
-   *
-   * @param string $method    The method name
-   * @param array  $arguments The array of arguments
-   *
-   * @return mixed The return value returned by the associated template instance method
-   */
-  public function __call($method, $arguments)
-  {
-    if (!method_exists($this->engine, $method))
-    {
-      throw new \RuntimeException(sprintf('Call to undefined method %s::%s().', get_class($this->engine), $method));
-    }
-
-    return call_user_func_array(array($this->engine, $method), $arguments);
-  }
-
-  /**
-   * Forwards the call to the associated template instance.
-   *
-   * @param string $name The property name
-   *
-   * @return mixed The value returned by the associated template instance
-   */
-  public function __get($name)
-  {
-    return $this->engine->$name;
-  }
 }
 }

+ 4 - 4
tests/unit/Symfony/Components/Templating/EngineTest.php

@@ -191,13 +191,13 @@ catch (InvalidArgumentException $e)
 }
 }
 
 
 $engine->getHelperSet()->set(new SimpleHelper('bar'));
 $engine->getHelperSet()->set(new SimpleHelper('bar'));
-$loader->setTemplate('foo.php', '<?php $this->extend("layout"); echo $this->foo.$foo ?>');
-$loader->setTemplate('layout.php', '-<?php echo $this->get("content") ?>-');
+$loader->setTemplate('foo.php', '<?php $view->extend("layout"); echo $view->foo.$foo ?>');
+$loader->setTemplate('layout.php', '-<?php echo $view->get("content") ?>-');
 $t->is($engine->render('foo', array('foo' => 'foo')), '-barfoo-', '->render() uses the decorator to decorate the template');
 $t->is($engine->render('foo', array('foo' => 'foo')), '-barfoo-', '->render() uses the decorator to decorate the template');
 
 
 $loader->setTemplate('bar.php', 'bar');
 $loader->setTemplate('bar.php', 'bar');
-$loader->setTemplate('foo.php', '<?php $this->extend("layout"); echo $foo ?>');
-$loader->setTemplate('layout.php', '<?php echo $this->render("bar") ?>-<?php echo $this->get("content") ?>-');
+$loader->setTemplate('foo.php', '<?php $view->extend("layout"); echo $foo ?>');
+$loader->setTemplate('layout.php', '<?php echo $view->render("bar") ?>-<?php echo $view->get("content") ?>-');
 $t->is($engine->render('foo', array('foo' => 'foo', 'bar' => 'bar')), 'bar-foo-', '->render() supports render() calls in templates');
 $t->is($engine->render('foo', array('foo' => 'foo', 'bar' => 'bar')), 'bar-foo-', '->render() supports render() calls in templates');
 
 
 class CompilableTemplateLoader extends Loader implements CompilableLoaderInterface
 class CompilableTemplateLoader extends Loader implements CompilableLoaderInterface

+ 1 - 13
tests/unit/Symfony/Components/Templating/Renderer/RendererTest.php

@@ -18,7 +18,7 @@ use Symfony\Components\Templating\Renderer\Renderer;
 use Symfony\Components\Templating\Storage\Storage;
 use Symfony\Components\Templating\Storage\Storage;
 use Symfony\Components\Templating\Loader\FilesystemLoader;
 use Symfony\Components\Templating\Loader\FilesystemLoader;
 
 
-$t = new LimeTest(3);
+$t = new LimeTest(1);
 
 
 class ProjectTemplateRenderer extends Renderer
 class ProjectTemplateRenderer extends Renderer
 {
 {
@@ -42,15 +42,3 @@ $t->diag('->setEngine()');
 $renderer = new ProjectTemplateRenderer();
 $renderer = new ProjectTemplateRenderer();
 $renderer->setEngine($engine);
 $renderer->setEngine($engine);
 $t->ok($renderer->getEngine() === $engine, '->setEngine() sets the engine instance tied to this renderer');
 $t->ok($renderer->getEngine() === $engine, '->setEngine() sets the engine instance tied to this renderer');
-
-// __call()
-$t->diag('__call()');
-$renderer = new ProjectTemplateRenderer();
-$renderer->setEngine($engine);
-$t->is($renderer->get('foo'), 'bar', '__call() proxies to the embedded engine instance');
-
-// __get()
-$t->diag('__get()');
-$renderer = new ProjectTemplateRenderer();
-$renderer->setEngine($engine);
-$t->is((string) $renderer->bar, 'foo', '__get() proxies to the embedded engine instance');