summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2017-02-06 22:49:37 +0100
committerArnold Daniels <arnold@jasny.net>2017-02-06 22:49:37 +0100
commit2b74b4d0b4ed34d5a556ab87528f3dbec743d174 (patch)
treeecf5cca4bab8a1deaa54fbfd4e4e6d73ae6899c1
parent6d1865d32c2aaad83ff5d9b5182d7c705fbf59ee (diff)
downloadview-2b74b4d0b4ed34d5a556ab87528f3dbec743d174.zip
view-2b74b4d0b4ed34d5a556ab87528f3dbec743d174.tar.gz
view-2b74b4d0b4ed34d5a556ab87528f3dbec743d174.tar.bz2
Rename View::view() to View::output()
Minor fixes for View/Twig
-rw-r--r--src/View/Twig.php24
-rw-r--r--src/ViewInterface.php2
-rw-r--r--tests/View/TwigTest.php16
3 files changed, 15 insertions, 27 deletions
diff --git a/src/View/Twig.php b/src/View/Twig.php
index aba67e3..2c75a7f 100644
--- a/src/View/Twig.php
+++ b/src/View/Twig.php
@@ -135,17 +135,19 @@ class Twig implements ViewInterface
}
/**
- * Add a twig extension
+ * Get the filename
*
- * @param \Twig_ExtensionInterface $extension
- * @return $this
+ * @return string
*/
- public function addExtension(\Twig_ExtensionInterface $extension)
+ protected function getFilename($name)
{
- $this->getTwig()->addExtension($extension);
+ if (pathinfo($name, PATHINFO_EXTENSION) === '') {
+ $name .= substr($name, -1) === '/' ? 'index.html.twig' : '.html.twig';
+ }
+
+ return $name;
}
-
-
+
/**
* Render and output template
*
@@ -154,14 +156,12 @@ class Twig implements ViewInterface
* @param array $context Template context as associated array
* @return ResponseInterface
*/
- public function view(ResponseInterface $response, $name, array $context = [])
+ public function output(ResponseInterface $response, $name, array $context = [])
{
- if (!pathinfo($name, PATHINFO_EXTENSION)) {
- $name .= substr($name, -1) === '/' ? 'index.html.twig' : '.html.twig';
- }
+ $file = $this->getFilename($name);
$twig = $this->getTwig();
- $tmpl = $twig->loadTemplate($name);
+ $tmpl = $twig->loadTemplate($file);
$contents = $tmpl->render($context);
diff --git a/src/ViewInterface.php b/src/ViewInterface.php
index fe5a5a2..ed33260 100644
--- a/src/ViewInterface.php
+++ b/src/ViewInterface.php
@@ -27,5 +27,5 @@ interface ViewInterface
* @param array $context Template context as associated array
* @return ResponseInterface
*/
- public function view(ResponseInterface $response, $name, array $context = []);
+ public function output(ResponseInterface $response, $name, array $context = []);
}
diff --git a/tests/View/TwigTest.php b/tests/View/TwigTest.php
index 0313658..06782b9 100644
--- a/tests/View/TwigTest.php
+++ b/tests/View/TwigTest.php
@@ -194,18 +194,6 @@ class TwigTest extends TestCase
$view->addDefaultExtensions();
}
- public function testAddExtension()
- {
- $extension = $this->createMock(\Twig_ExtensionInterface::class);
-
- $twig = $this->createMock(\Twig_Environment::class);
- $twig->expects($this->once())->method('addExtension')->with($this->identicalTo($extension));
-
- $view = new TwigView($twig);
-
- $view->addExtension($extension);
- }
-
public function filenameProvider()
{
return [
@@ -223,7 +211,7 @@ class TwigTest extends TestCase
* @param string $name
* @param string $expect
*/
- public function testView($name, $expect)
+ public function testOutput($name, $expect)
{
$context = ['color' => 'blue', 'answer' => 42];
@@ -246,6 +234,6 @@ class TwigTest extends TestCase
$view = new TwigView($twig);
- $view->view($response, $name, $context);
+ $view->output($response, $name, $context);
}
}