diff options
author | Arnold Daniels <arnold@jasny.net> | 2017-02-06 22:49:37 +0100 |
---|---|---|
committer | Arnold Daniels <arnold@jasny.net> | 2017-02-06 22:49:37 +0100 |
commit | 2b74b4d0b4ed34d5a556ab87528f3dbec743d174 (patch) | |
tree | ecf5cca4bab8a1deaa54fbfd4e4e6d73ae6899c1 /src | |
parent | 6d1865d32c2aaad83ff5d9b5182d7c705fbf59ee (diff) | |
download | view-2b74b4d0b4ed34d5a556ab87528f3dbec743d174.zip view-2b74b4d0b4ed34d5a556ab87528f3dbec743d174.tar.gz view-2b74b4d0b4ed34d5a556ab87528f3dbec743d174.tar.bz2 |
Rename View::view() to View::output()
Minor fixes for View/Twig
Diffstat (limited to 'src')
-rw-r--r-- | src/View/Twig.php | 24 | ||||
-rw-r--r-- | src/ViewInterface.php | 2 |
2 files changed, 13 insertions, 13 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 = []); } |