diff --git a/src/Symfony/Components/Templating/Storage/FileStorage.php b/src/Symfony/Components/Templating/Storage/FileStorage.php index 160a5b7285..9cc74f74ce 100644 --- a/src/Symfony/Components/Templating/Storage/FileStorage.php +++ b/src/Symfony/Components/Templating/Storage/FileStorage.php @@ -20,4 +20,8 @@ namespace Symfony\Components\Templating\Storage; */ class FileStorage extends Storage { + public function getContent() + { + return file_get_contents($this->template); + } } diff --git a/src/Symfony/Components/Templating/Storage/Storage.php b/src/Symfony/Components/Templating/Storage/Storage.php index 071c766d6a..157e0f15ec 100644 --- a/src/Symfony/Components/Templating/Storage/Storage.php +++ b/src/Symfony/Components/Templating/Storage/Storage.php @@ -18,7 +18,7 @@ namespace Symfony\Components\Templating\Storage; * @subpackage templating * @author Fabien Potencier */ -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. * diff --git a/src/Symfony/Components/Templating/Storage/StringStorage.php b/src/Symfony/Components/Templating/Storage/StringStorage.php index 651cc650e4..b14a003450 100644 --- a/src/Symfony/Components/Templating/Storage/StringStorage.php +++ b/src/Symfony/Components/Templating/Storage/StringStorage.php @@ -20,4 +20,8 @@ namespace Symfony\Components\Templating\Storage; */ class StringStorage extends Storage { + public function getContent() + { + return $this->template; + } } diff --git a/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php b/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php index 314e6bf252..86c02afb5e 100644 --- a/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php +++ b/tests/unit/Symfony/Components/Templating/Storage/FileStorageTest.php @@ -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(), '', '->getContent() returns the content of the template'); diff --git a/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php b/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php index ad7de8d104..a4f398ea27 100644 --- a/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php +++ b/tests/unit/Symfony/Components/Templating/Storage/StorageTest.php @@ -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'); diff --git a/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php b/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php index 86f2c78f82..3b18b80845 100644 --- a/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php +++ b/tests/unit/Symfony/Components/Templating/Storage/StringStorageTest.php @@ -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');