Example #1
0
use Symfony\Components\Templating\Engine;
use Symfony\Components\Templating\Renderer\Renderer;
use Symfony\Components\Templating\Storage\Storage;
use Symfony\Components\Templating\Loader\FilesystemLoader;

$t = new LimeTest(1);

class ProjectTemplateRenderer extends Renderer
{
  public function getEngine()
  {
    return $this->engine;
  }

  public function evaluate(Storage $template, array $parameters = array())
  {
  }
}

$loader = new FilesystemLoader(array(__DIR__.'/fixtures/templates/%name%.%renderer%'));
$engine = new Engine($loader);
$engine->set('foo', 'bar');
$engine->getHelperSet()->set(new SimpleHelper('foo'), 'bar');

// ->setEngine()
$t->diag('->setEngine()');
$renderer = new ProjectTemplateRenderer();
$renderer->setEngine($engine);
$t->ok($renderer->getEngine() === $engine, '->setEngine() sets the engine instance tied to this renderer');
require_once dirname(__FILE__) . '/lib/SimpleHelper.php';
$t = new lime_test(3);
class ProjectTemplateRenderer extends sfTemplateRenderer
{
    public function getEngine()
    {
        return $this->engine;
    }
    public function evaluate(sfTemplateStorage $template, array $parameters = array())
    {
    }
}
$loader = new sfTemplateLoaderFilesystem(array(dirname(__FILE__) . '/fixtures/templates/%name%.%renderer%'));
$engine = new sfTemplateEngine($loader);
$engine->set('foo', 'bar');
$engine->getHelperSet()->set(new SimpleHelper('foo'), 'bar');
// ->setEngine()
$t->diag('->setEngine()');
$renderer = new ProjectTemplateRenderer();
$renderer->setEngine($engine);
$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');
{
    public $templates = array();
    public function setTemplate($name, $template)
    {
        $this->templates[$name] = $template;
    }
    public function load($template, $renderer = 'php')
    {
        if (isset($this->templates[$template . '.' . $renderer])) {
            return new sfTemplateStorageString($this->templates[$template . '.' . $renderer]);
        }
        return false;
    }
}
$loader = new ProjectTemplateLoader();
$renderer = new ProjectTemplateRenderer();
// __construct()
$t->diag('__construct()');
$engine = new ProjectTemplateEngine($loader);
$t->is($engine->getLoader(), $loader, '__construct() takes a loader instance as its second first argument');
$t->is(array_keys($engine->getRenderers()), array('php'), '__construct() automatically registers a PHP renderer if none is given');
$t->ok($engine->getHelperSet() instanceof sfTemplateHelperSet, '__construct() automatically creates a helper set if none is given');
$engine = new ProjectTemplateEngine($loader, array('foo' => $renderer));
$t->is(array_keys($engine->getRenderers()), array('foo', 'php'), '__construct() takes an array of renderers as its third argument');
$t->ok($renderer->getEngine() === $engine, '__construct() registers itself on all renderers');
$engine = new ProjectTemplateEngine($loader, array('php' => $renderer));
$t->ok($engine->getRenderers() === array('php' => $renderer), '__construct() can overridde the default PHP renderer');
$engine = new ProjectTemplateEngine($loader, array(), $helperSet = new sfTemplateHelperSet());
$t->ok($engine->getHelperSet() === $helperSet, '__construct() takes a helper set as its third argument');
// ->getHelperSet() ->setHelperSet()
$t->diag('->getHelperSet() ->setHelperSet()');