@@ -16,8 +16,8 @@ |
||
| 16 | 16 | interface TemplateSpecifyingViewModel |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public function getTemplateName(); |
|
| 19 | + /** |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public function getTemplateName(); |
|
| 23 | 23 | } |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | interface TemplateManager |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param string $template_name Name of the template to use (can include path separators) |
|
| 22 | - * |
|
| 23 | - * @return string Path to the compiled template file |
|
| 24 | - */ |
|
| 25 | - public function getPath($template_name); |
|
| 20 | + /** |
|
| 21 | + * @param string $template_name Name of the template to use (can include path separators) |
|
| 22 | + * |
|
| 23 | + * @return string Path to the compiled template file |
|
| 24 | + */ |
|
| 25 | + public function getPath($template_name); |
|
| 26 | 26 | |
| 27 | 27 | } |
@@ -15,11 +15,11 @@ |
||
| 15 | 15 | class CFSWrapper |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @see \Kohana::find_file |
|
| 20 | - */ |
|
| 21 | - public function find_file($dir, $file) |
|
| 22 | - { |
|
| 23 | - return \Kohana::find_file($dir, $file, NULL, FALSE); |
|
| 24 | - } |
|
| 18 | + /** |
|
| 19 | + * @see \Kohana::find_file |
|
| 20 | + */ |
|
| 21 | + public function find_file($dir, $file) |
|
| 22 | + { |
|
| 23 | + return \Kohana::find_file($dir, $file, NULL, FALSE); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -17,11 +17,11 @@ |
||
| 17 | 17 | interface Renderer |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param ViewModel $view |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function render(ViewModel $view); |
|
| 20 | + /** |
|
| 21 | + * @param ViewModel $view |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function render(ViewModel $view); |
|
| 26 | 26 | |
| 27 | 27 | } |
@@ -77,11 +77,11 @@ |
||
| 77 | 77 | { |
| 78 | 78 | /** @noinspection PhpUnusedParameterInspection */ |
| 79 | 79 | /** @noinspection PhpDocSignatureInspection */ |
| 80 | - $bound_capture = function (ViewModel $view, Renderer $renderer, $template) { |
|
| 80 | + $bound_capture = function(ViewModel $view, Renderer $renderer, $template) { |
|
| 81 | 81 | /** @noinspection PhpIncludeInspection */ |
| 82 | 82 | return include $template; |
| 83 | 83 | }; |
| 84 | - $anon_capture = $bound_capture->bindTo(NULL); |
|
| 84 | + $anon_capture = $bound_capture->bindTo(NULL); |
|
| 85 | 85 | |
| 86 | 86 | // A user's own error handler may throw an exception here if the include fails - which we will bubble as-is. |
| 87 | 87 | // If they have not configured an error handler, we need to throw an exception of our own. |
@@ -23,72 +23,72 @@ |
||
| 23 | 23 | class HTMLRenderer implements Renderer |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var TemplateManager |
|
| 28 | - */ |
|
| 29 | - protected $template_manager; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var ViewTemplateSelector |
|
| 33 | - */ |
|
| 34 | - protected $template_selector; |
|
| 35 | - |
|
| 36 | - public function __construct(ViewTemplateSelector $template_selector, TemplateManager $template_manager) |
|
| 37 | - { |
|
| 38 | - $this->template_selector = $template_selector; |
|
| 39 | - $this->template_manager = $template_manager; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * {@inheritdoc} |
|
| 45 | - */ |
|
| 46 | - public function render(ViewModel $view) |
|
| 47 | - { |
|
| 48 | - $template_path = $this->getTemplatePath($view); |
|
| 49 | - |
|
| 50 | - ob_start(); |
|
| 51 | - try { |
|
| 52 | - $this->includeWithAnonymousScope($view, $template_path); |
|
| 53 | - } finally { |
|
| 54 | - $output = ob_get_clean(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - return $output; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param ViewModel $view |
|
| 62 | - * |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - protected function getTemplatePath(ViewModel $view) |
|
| 66 | - { |
|
| 67 | - $template_name = $this->template_selector->getTemplateName($view); |
|
| 68 | - $template = $this->template_manager->getPath($template_name); |
|
| 69 | - |
|
| 70 | - return $template; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param ViewModel $view |
|
| 75 | - * @param string $template_path |
|
| 76 | - */ |
|
| 77 | - protected function includeWithAnonymousScope(ViewModel $view, $template_path) |
|
| 78 | - { |
|
| 79 | - /** @noinspection PhpUnusedParameterInspection */ |
|
| 80 | - /** @noinspection PhpDocSignatureInspection */ |
|
| 81 | - $bound_capture = function (ViewModel $view, Renderer $renderer, $template) { |
|
| 82 | - /** @noinspection PhpIncludeInspection */ |
|
| 83 | - return include $template; |
|
| 84 | - }; |
|
| 85 | - $anon_capture = $bound_capture->bindTo(NULL); |
|
| 86 | - |
|
| 87 | - // A user's own error handler may throw an exception here if the include fails - which we will bubble as-is. |
|
| 88 | - // If they have not configured an error handler, we need to throw an exception of our own. |
|
| 89 | - if ($anon_capture($view, $this, $template_path) === FALSE) { |
|
| 90 | - throw TemplateNotFoundException::forFullPath($template_path); |
|
| 91 | - } |
|
| 92 | - } |
|
| 26 | + /** |
|
| 27 | + * @var TemplateManager |
|
| 28 | + */ |
|
| 29 | + protected $template_manager; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var ViewTemplateSelector |
|
| 33 | + */ |
|
| 34 | + protected $template_selector; |
|
| 35 | + |
|
| 36 | + public function __construct(ViewTemplateSelector $template_selector, TemplateManager $template_manager) |
|
| 37 | + { |
|
| 38 | + $this->template_selector = $template_selector; |
|
| 39 | + $this->template_manager = $template_manager; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * {@inheritdoc} |
|
| 45 | + */ |
|
| 46 | + public function render(ViewModel $view) |
|
| 47 | + { |
|
| 48 | + $template_path = $this->getTemplatePath($view); |
|
| 49 | + |
|
| 50 | + ob_start(); |
|
| 51 | + try { |
|
| 52 | + $this->includeWithAnonymousScope($view, $template_path); |
|
| 53 | + } finally { |
|
| 54 | + $output = ob_get_clean(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + return $output; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param ViewModel $view |
|
| 62 | + * |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + protected function getTemplatePath(ViewModel $view) |
|
| 66 | + { |
|
| 67 | + $template_name = $this->template_selector->getTemplateName($view); |
|
| 68 | + $template = $this->template_manager->getPath($template_name); |
|
| 69 | + |
|
| 70 | + return $template; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param ViewModel $view |
|
| 75 | + * @param string $template_path |
|
| 76 | + */ |
|
| 77 | + protected function includeWithAnonymousScope(ViewModel $view, $template_path) |
|
| 78 | + { |
|
| 79 | + /** @noinspection PhpUnusedParameterInspection */ |
|
| 80 | + /** @noinspection PhpDocSignatureInspection */ |
|
| 81 | + $bound_capture = function (ViewModel $view, Renderer $renderer, $template) { |
|
| 82 | + /** @noinspection PhpIncludeInspection */ |
|
| 83 | + return include $template; |
|
| 84 | + }; |
|
| 85 | + $anon_capture = $bound_capture->bindTo(NULL); |
|
| 86 | + |
|
| 87 | + // A user's own error handler may throw an exception here if the include fails - which we will bubble as-is. |
|
| 88 | + // If they have not configured an error handler, we need to throw an exception of our own. |
|
| 89 | + if ($anon_capture($view, $this, $template_path) === FALSE) { |
|
| 90 | + throw TemplateNotFoundException::forFullPath($template_path); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | 94 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | interface PageContentView extends ViewModel |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The page layout that this content view will be rendered into |
|
| 26 | - * |
|
| 27 | - * @return PageLayoutView |
|
| 28 | - */ |
|
| 29 | - public function var_page(); |
|
| 24 | + /** |
|
| 25 | + * The page layout that this content view will be rendered into |
|
| 26 | + * |
|
| 27 | + * @return PageLayoutView |
|
| 28 | + */ |
|
| 29 | + public function var_page(); |
|
| 30 | 30 | } |
@@ -26,32 +26,32 @@ |
||
| 26 | 26 | abstract class AbstractPageLayoutView extends AbstractViewModel implements ViewModel\PageLayoutView |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $variables = [ |
|
| 33 | - 'body_html' => NULL, |
|
| 34 | - 'title' => NULL, |
|
| 35 | - ]; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param string $title |
|
| 39 | - * |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function setTitle($title) |
|
| 43 | - { |
|
| 44 | - $this->variables['title'] = $title; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string $html |
|
| 49 | - * |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public function setBodyHTML($html) |
|
| 53 | - { |
|
| 54 | - $this->variables['body_html'] = $html; |
|
| 55 | - } |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $variables = [ |
|
| 33 | + 'body_html' => NULL, |
|
| 34 | + 'title' => NULL, |
|
| 35 | + ]; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param string $title |
|
| 39 | + * |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function setTitle($title) |
|
| 43 | + { |
|
| 44 | + $this->variables['title'] = $title; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string $html |
|
| 49 | + * |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public function setBodyHTML($html) |
|
| 53 | + { |
|
| 54 | + $this->variables['body_html'] = $html; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | } |
@@ -27,23 +27,23 @@ |
||
| 27 | 27 | abstract class AbstractPageContentView extends AbstractViewModel implements PageContentView |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var PageLayoutView |
|
| 32 | - */ |
|
| 33 | - protected $page_view; |
|
| 34 | - |
|
| 35 | - public function __construct(PageLayoutView $page) |
|
| 36 | - { |
|
| 37 | - $this->page_view = $page; |
|
| 38 | - parent::__construct(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return PageLayoutView |
|
| 43 | - */ |
|
| 44 | - public function var_page() |
|
| 45 | - { |
|
| 46 | - return $this->page_view; |
|
| 47 | - } |
|
| 30 | + /** |
|
| 31 | + * @var PageLayoutView |
|
| 32 | + */ |
|
| 33 | + protected $page_view; |
|
| 34 | + |
|
| 35 | + public function __construct(PageLayoutView $page) |
|
| 36 | + { |
|
| 37 | + $this->page_view = $page; |
|
| 38 | + parent::__construct(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return PageLayoutView |
|
| 43 | + */ |
|
| 44 | + public function var_page() |
|
| 45 | + { |
|
| 46 | + return $this->page_view; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * @author Andrew Coulton <[email protected]> |
|
| 4 | - * @copyright 2015 inGenerator Ltd |
|
| 5 | - * @license http://kohanaframework.org/license |
|
| 6 | - */ |
|
| 3 | + * @author Andrew Coulton <[email protected]> |
|
| 4 | + * @copyright 2015 inGenerator Ltd |
|
| 5 | + * @license http://kohanaframework.org/license |
|
| 6 | + */ |
|
| 7 | 7 | |
| 8 | 8 | namespace Ingenerator\KohanaView\Renderer; |
| 9 | 9 | |
@@ -34,82 +34,82 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | class PageLayoutRenderer |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * @var bool Whether to force (or not force) embedding the content in the layout |
|
| 39 | - */ |
|
| 40 | - protected $use_layout; |
|
| 37 | + /** |
|
| 38 | + * @var bool Whether to force (or not force) embedding the content in the layout |
|
| 39 | + */ |
|
| 40 | + protected $use_layout; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var Renderer |
|
| 44 | - */ |
|
| 45 | - protected $view_renderer; |
|
| 42 | + /** |
|
| 43 | + * @var Renderer |
|
| 44 | + */ |
|
| 45 | + protected $view_renderer; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var \Request |
|
| 49 | - */ |
|
| 50 | - protected $current_request; |
|
| 47 | + /** |
|
| 48 | + * @var \Request |
|
| 49 | + */ |
|
| 50 | + protected $current_request; |
|
| 51 | 51 | |
| 52 | - public function __construct(Renderer $view_renderer, \Request $current_request = NULL) |
|
| 53 | - { |
|
| 54 | - $this->view_renderer = $view_renderer; |
|
| 55 | - $this->current_request = $current_request; |
|
| 56 | - } |
|
| 52 | + public function __construct(Renderer $view_renderer, \Request $current_request = NULL) |
|
| 53 | + { |
|
| 54 | + $this->view_renderer = $view_renderer; |
|
| 55 | + $this->current_request = $current_request; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param PageContentView $content_view |
|
| 60 | - * |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function render(PageContentView $content_view) |
|
| 64 | - { |
|
| 65 | - $content = $this->view_renderer->render($content_view); |
|
| 66 | - if ($this->shouldUseLayout()) { |
|
| 67 | - return $this->renderInLayout($content_view->var_page(), $content); |
|
| 68 | - } else { |
|
| 69 | - return $content; |
|
| 70 | - } |
|
| 71 | - } |
|
| 58 | + /** |
|
| 59 | + * @param PageContentView $content_view |
|
| 60 | + * |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function render(PageContentView $content_view) |
|
| 64 | + { |
|
| 65 | + $content = $this->view_renderer->render($content_view); |
|
| 66 | + if ($this->shouldUseLayout()) { |
|
| 67 | + return $this->renderInLayout($content_view->var_page(), $content); |
|
| 68 | + } else { |
|
| 69 | + return $content; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return bool |
|
| 75 | - */ |
|
| 76 | - protected function shouldUseLayout() |
|
| 77 | - { |
|
| 78 | - if ($this->use_layout !== NULL) { |
|
| 79 | - return $this->use_layout; |
|
| 80 | - } |
|
| 73 | + /** |
|
| 74 | + * @return bool |
|
| 75 | + */ |
|
| 76 | + protected function shouldUseLayout() |
|
| 77 | + { |
|
| 78 | + if ($this->use_layout !== NULL) { |
|
| 79 | + return $this->use_layout; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if ($this->current_request AND $this->current_request->is_ajax()) { |
|
| 83 | - return FALSE; |
|
| 84 | - } else { |
|
| 85 | - return TRUE; |
|
| 86 | - } |
|
| 87 | - } |
|
| 82 | + if ($this->current_request AND $this->current_request->is_ajax()) { |
|
| 83 | + return FALSE; |
|
| 84 | + } else { |
|
| 85 | + return TRUE; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @param PageLayoutView $layout |
|
| 91 | - * @param string $content |
|
| 92 | - * |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - protected function renderInLayout(PageLayoutView $layout, $content) |
|
| 96 | - { |
|
| 97 | - $layout->setBodyHTML($content); |
|
| 89 | + /** |
|
| 90 | + * @param PageLayoutView $layout |
|
| 91 | + * @param string $content |
|
| 92 | + * |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + protected function renderInLayout(PageLayoutView $layout, $content) |
|
| 96 | + { |
|
| 97 | + $layout->setBodyHTML($content); |
|
| 98 | 98 | |
| 99 | - return $this->view_renderer->render($layout); |
|
| 100 | - } |
|
| 99 | + return $this->view_renderer->render($layout); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Configure whether to always wrap the content in the layout (TRUE), never (FALSE) or automatically for |
|
| 104 | - * non-AJAX requests (NULL) |
|
| 105 | - * |
|
| 106 | - * @param bool $use_layout |
|
| 107 | - * |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public function setUseLayout($use_layout) |
|
| 111 | - { |
|
| 112 | - $this->use_layout = $use_layout; |
|
| 113 | - } |
|
| 102 | + /** |
|
| 103 | + * Configure whether to always wrap the content in the layout (TRUE), never (FALSE) or automatically for |
|
| 104 | + * non-AJAX requests (NULL) |
|
| 105 | + * |
|
| 106 | + * @param bool $use_layout |
|
| 107 | + * |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public function setUseLayout($use_layout) |
|
| 111 | + { |
|
| 112 | + $this->use_layout = $use_layout; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |