@@ -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 | } |
@@ -1,9 +1,9 @@ |
||
| 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; |
| 9 | 9 | |
@@ -18,61 +18,61 @@ |
||
| 18 | 18 | class ViewTemplateSelector |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param ViewModel $view |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function getTemplateName(ViewModel $view) |
|
| 27 | - { |
|
| 28 | - if ($view instanceof TemplateSpecifyingViewModel) { |
|
| 29 | - return $this->validateSpecifiedTemplateName($view); |
|
| 30 | - } else { |
|
| 31 | - return $this->calculateTemplateFromClassName($view); |
|
| 32 | - } |
|
| 33 | - } |
|
| 21 | + /** |
|
| 22 | + * @param ViewModel $view |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function getTemplateName(ViewModel $view) |
|
| 27 | + { |
|
| 28 | + if ($view instanceof TemplateSpecifyingViewModel) { |
|
| 29 | + return $this->validateSpecifiedTemplateName($view); |
|
| 30 | + } else { |
|
| 31 | + return $this->calculateTemplateFromClassName($view); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param TemplateSpecifyingViewModel $view |
|
| 37 | - * |
|
| 38 | - * @return mixed |
|
| 39 | - * @throws \UnexpectedValueException if no template is provided |
|
| 40 | - */ |
|
| 41 | - protected function validateSpecifiedTemplateName(TemplateSpecifyingViewModel $view) |
|
| 42 | - { |
|
| 43 | - $template = $view->getTemplateName(); |
|
| 44 | - $view_class = get_class($view); |
|
| 45 | - if ( ! $template) { |
|
| 46 | - throw new \UnexpectedValueException( |
|
| 47 | - "$view_class::getTemplateName() must return a template name, empty value returned" |
|
| 48 | - ); |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * @param TemplateSpecifyingViewModel $view |
|
| 37 | + * |
|
| 38 | + * @return mixed |
|
| 39 | + * @throws \UnexpectedValueException if no template is provided |
|
| 40 | + */ |
|
| 41 | + protected function validateSpecifiedTemplateName(TemplateSpecifyingViewModel $view) |
|
| 42 | + { |
|
| 43 | + $template = $view->getTemplateName(); |
|
| 44 | + $view_class = get_class($view); |
|
| 45 | + if ( ! $template) { |
|
| 46 | + throw new \UnexpectedValueException( |
|
| 47 | + "$view_class::getTemplateName() must return a template name, empty value returned" |
|
| 48 | + ); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if ( ! is_string($template)) { |
|
| 52 | - $type = is_object($template) ? get_class($template) : gettype($template); |
|
| 53 | - throw new \UnexpectedValueException( |
|
| 54 | - "$view_class::getTemplateName() must return a string template name, $type value returned" |
|
| 55 | - ); |
|
| 56 | - } |
|
| 51 | + if ( ! is_string($template)) { |
|
| 52 | + $type = is_object($template) ? get_class($template) : gettype($template); |
|
| 53 | + throw new \UnexpectedValueException( |
|
| 54 | + "$view_class::getTemplateName() must return a string template name, $type value returned" |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $template; |
|
| 59 | - } |
|
| 58 | + return $template; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param ViewModel $view |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - protected function calculateTemplateFromClassName(ViewModel $view) |
|
| 67 | - { |
|
| 68 | - $template = preg_replace('/\\\\|_/', '/', get_class($view)); |
|
| 69 | - $template = preg_replace('/([a-z])([A-Z])/', '\1_\2', $template); |
|
| 70 | - $template = strtolower($template); |
|
| 71 | - if (substr($template, 0, 5) === 'view/') { |
|
| 72 | - $template = substr($template, 5); |
|
| 73 | - } |
|
| 61 | + /** |
|
| 62 | + * @param ViewModel $view |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + protected function calculateTemplateFromClassName(ViewModel $view) |
|
| 67 | + { |
|
| 68 | + $template = preg_replace('/\\\\|_/', '/', get_class($view)); |
|
| 69 | + $template = preg_replace('/([a-z])([A-Z])/', '\1_\2', $template); |
|
| 70 | + $template = strtolower($template); |
|
| 71 | + if (substr($template, 0, 5) === 'view/') { |
|
| 72 | + $template = substr($template, 5); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - return $template; |
|
| 76 | - } |
|
| 75 | + return $template; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |