[Templating] added a getContent() method to the Storage class

This commit is contained in:
Fabien Potencier 2010-02-02 14:01:02 +01:00
parent 3caa805c48
commit e5f8da4ead
6 changed files with 33 additions and 5 deletions

View File

@ -20,4 +20,8 @@ namespace Symfony\Components\Templating\Storage;
*/
class FileStorage extends Storage
{
public function getContent()
{
return file_get_contents($this->template);
}
}

View File

@ -18,7 +18,7 @@ namespace Symfony\Components\Templating\Storage;
* @subpackage templating
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Storage
abstract class Storage
{
protected $renderer;
protected $template;
@ -44,6 +44,8 @@ class Storage
return (string) $this->template;
}
abstract public function getContent();
/**
* Gets the renderer.
*

View File

@ -20,4 +20,8 @@ namespace Symfony\Components\Templating\Storage;
*/
class StringStorage extends Storage
{
public function getContent()
{
return $this->template;
}
}

View File

@ -14,7 +14,12 @@ require_once __DIR__.'/../../../../bootstrap.php';
use Symfony\Components\Templating\Storage\Storage;
use Symfony\Components\Templating\Storage\FileStorage;
$t = new LimeTest(1);
$t = new LimeTest(2);
$storage = new FileStorage('foo');
$t->ok($storage instanceof Storage, 'FileStorage is an instance of Storage');
// ->getContent()
$t->diag('->getContent()');
$storage = new FileStorage(__DIR__.'/../../../../../fixtures/Symfony/Components/Templating/templates/foo.php');
$t->is($storage->getContent(), '<?php echo $foo ?>', '->getContent() returns the content of the template');

View File

@ -16,13 +16,20 @@ use Symfony\Components\Templating\Renderer\PhpRenderer;
$t = new LimeTest(2);
class TestStorage extends Storage
{
public function getContent()
{
}
}
// __construct() __toString()
$t->diag('__construct() __toString()');
$storage = new Storage('foo');
$storage = new TestStorage('foo');
$t->is((string) $storage, 'foo', '__toString() returns the template name');
// ->getRenderer()
$t->diag('->getRenderer()');
$storage = new Storage('foo', $renderer = new PhpRenderer());
$storage = new TestStorage('foo', $renderer = new PhpRenderer());
$t->ok($storage->getRenderer() === $renderer, '->getRenderer() returns the renderer');

View File

@ -14,7 +14,13 @@ require_once __DIR__.'/../../../../bootstrap.php';
use Symfony\Components\Templating\Storage\Storage;
use Symfony\Components\Templating\Storage\StringStorage;
$t = new LimeTest(1);
$t = new LimeTest(2);
$storage = new StringStorage('foo');
$t->ok($storage instanceof Storage, 'StringStorage is an instance of Storage');
// ->getContent()
$t->diag('->getContent()');
$storage = new StringStorage('foo');
$t->is($storage->getContent(), 'foo', '->getContent() returns the content of the template');