[Templating] added a getContent() method to the Storage class
This commit is contained in:
parent
3caa805c48
commit
e5f8da4ead
@ -20,4 +20,8 @@ namespace Symfony\Components\Templating\Storage;
|
||||
*/
|
||||
class FileStorage extends Storage
|
||||
{
|
||||
public function getContent()
|
||||
{
|
||||
return file_get_contents($this->template);
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -20,4 +20,8 @@ namespace Symfony\Components\Templating\Storage;
|
||||
*/
|
||||
class StringStorage extends Storage
|
||||
{
|
||||
public function getContent()
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -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');
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user