@@ -16,20 +16,20 @@ |
||
16 | 16 | class InvalidDisplayVariablesException extends \InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param string $view_class |
|
21 | - * @param string $errors |
|
22 | - * |
|
23 | - * @return static |
|
24 | - */ |
|
25 | - public static function passedToDisplay($view_class, $errors) |
|
26 | - { |
|
27 | - return new static( |
|
28 | - sprintf( |
|
29 | - "Invalid variables provided to %s::display()\n%s", |
|
30 | - $view_class, |
|
31 | - ' - '.implode("\n - ", $errors) |
|
32 | - ) |
|
33 | - ); |
|
34 | - } |
|
19 | + /** |
|
20 | + * @param string $view_class |
|
21 | + * @param string $errors |
|
22 | + * |
|
23 | + * @return static |
|
24 | + */ |
|
25 | + public static function passedToDisplay($view_class, $errors) |
|
26 | + { |
|
27 | + return new static( |
|
28 | + sprintf( |
|
29 | + "Invalid variables provided to %s::display()\n%s", |
|
30 | + $view_class, |
|
31 | + ' - '.implode("\n - ", $errors) |
|
32 | + ) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | } |
@@ -16,16 +16,16 @@ |
||
16 | 16 | class InvalidViewVarAssignmentException extends \BadMethodCallException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param string $view_class |
|
21 | - * @param string $var_name |
|
22 | - * |
|
23 | - * @return static |
|
24 | - */ |
|
25 | - public static function forReadOnlyVar($view_class, $var_name) |
|
26 | - { |
|
27 | - return new static( |
|
28 | - $view_class.' variables are read-only, cannot assign '.$var_name |
|
29 | - ); |
|
30 | - } |
|
19 | + /** |
|
20 | + * @param string $view_class |
|
21 | + * @param string $var_name |
|
22 | + * |
|
23 | + * @return static |
|
24 | + */ |
|
25 | + public static function forReadOnlyVar($view_class, $var_name) |
|
26 | + { |
|
27 | + return new static( |
|
28 | + $view_class.' variables are read-only, cannot assign '.$var_name |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | } |
@@ -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\Exception; |
9 | 9 | |
@@ -15,26 +15,26 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class TemplateCacheException extends \RuntimeException |
17 | 17 | { |
18 | - /** |
|
19 | - * @param string $path |
|
20 | - * |
|
21 | - * @return static |
|
22 | - */ |
|
23 | - public static function cannotCreateDirectory($path) |
|
24 | - { |
|
25 | - return new static( |
|
26 | - "Cannot create template cache directory in '$path'" |
|
27 | - ); |
|
28 | - } |
|
18 | + /** |
|
19 | + * @param string $path |
|
20 | + * |
|
21 | + * @return static |
|
22 | + */ |
|
23 | + public static function cannotCreateDirectory($path) |
|
24 | + { |
|
25 | + return new static( |
|
26 | + "Cannot create template cache directory in '$path'" |
|
27 | + ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $path |
|
32 | - * |
|
33 | - * @return static |
|
34 | - */ |
|
35 | - public static function pathNotWriteable($path) |
|
36 | - { |
|
37 | - return new static("Cannot write to compiled template path '$path'"); |
|
38 | - } |
|
30 | + /** |
|
31 | + * @param string $path |
|
32 | + * |
|
33 | + * @return static |
|
34 | + */ |
|
35 | + public static function pathNotWriteable($path) |
|
36 | + { |
|
37 | + return new static("Cannot write to compiled template path '$path'"); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | } |
@@ -15,27 +15,27 @@ |
||
15 | 15 | class TemplateNotFoundException extends \InvalidArgumentException |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $path |
|
20 | - * |
|
21 | - * @return static |
|
22 | - */ |
|
23 | - public static function forFullPath($path) |
|
24 | - { |
|
25 | - return new static( |
|
26 | - "Failed to include template '$path'" |
|
27 | - ); |
|
28 | - } |
|
18 | + /** |
|
19 | + * @param string $path |
|
20 | + * |
|
21 | + * @return static |
|
22 | + */ |
|
23 | + public static function forFullPath($path) |
|
24 | + { |
|
25 | + return new static( |
|
26 | + "Failed to include template '$path'" |
|
27 | + ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param string $rel_path |
|
32 | - * |
|
33 | - * @return static |
|
34 | - */ |
|
35 | - public static function forSourcePath($rel_path) |
|
36 | - { |
|
37 | - return new static( |
|
38 | - "Cannot find template source file '$rel_path'" |
|
39 | - ); |
|
40 | - } |
|
30 | + /** |
|
31 | + * @param string $rel_path |
|
32 | + * |
|
33 | + * @return static |
|
34 | + */ |
|
35 | + public static function forSourcePath($rel_path) |
|
36 | + { |
|
37 | + return new static( |
|
38 | + "Cannot find template source file '$rel_path'" |
|
39 | + ); |
|
40 | + } |
|
41 | 41 | } |
@@ -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\Exception; |
9 | 9 | |
@@ -16,25 +16,25 @@ discard block |
||
16 | 16 | class UnassignedViewVarException extends \BadMethodCallException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param string $view_class |
|
21 | - * @param string $var_name |
|
22 | - * @param string $hint |
|
23 | - * |
|
24 | - * @return static |
|
25 | - */ |
|
26 | - public static function forVariable($view_class, $var_name, $hint) |
|
27 | - { |
|
28 | - return new static( |
|
29 | - sprintf( |
|
30 | - 'Call %s::display(["%s" => "%s"]) before rendering a %s view', |
|
31 | - $view_class, |
|
32 | - $var_name, |
|
33 | - $hint, |
|
34 | - $view_class |
|
35 | - ) |
|
36 | - ); |
|
37 | - } |
|
19 | + /** |
|
20 | + * @param string $view_class |
|
21 | + * @param string $var_name |
|
22 | + * @param string $hint |
|
23 | + * |
|
24 | + * @return static |
|
25 | + */ |
|
26 | + public static function forVariable($view_class, $var_name, $hint) |
|
27 | + { |
|
28 | + return new static( |
|
29 | + sprintf( |
|
30 | + 'Call %s::display(["%s" => "%s"]) before rendering a %s view', |
|
31 | + $view_class, |
|
32 | + $var_name, |
|
33 | + $hint, |
|
34 | + $view_class |
|
35 | + ) |
|
36 | + ); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 | } |
@@ -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\Exception; |
9 | 9 | |
@@ -16,33 +16,33 @@ discard block |
||
16 | 16 | class UnspecifiedTemplateNameException extends \UnexpectedValueException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param string $view_class |
|
21 | - * |
|
22 | - * @return static |
|
23 | - */ |
|
24 | - public static function forEmptyValue($view_class) |
|
25 | - { |
|
26 | - return new static( |
|
27 | - $view_class.'::getTemplateName() must return a template name, empty value returned' |
|
28 | - ); |
|
29 | - } |
|
19 | + /** |
|
20 | + * @param string $view_class |
|
21 | + * |
|
22 | + * @return static |
|
23 | + */ |
|
24 | + public static function forEmptyValue($view_class) |
|
25 | + { |
|
26 | + return new static( |
|
27 | + $view_class.'::getTemplateName() must return a template name, empty value returned' |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param string $view_class |
|
33 | - * @param string $template |
|
34 | - * |
|
35 | - * @return static |
|
36 | - */ |
|
37 | - public static function forNonStringValue($view_class, $template) |
|
38 | - { |
|
39 | - return new static( |
|
40 | - sprintf( |
|
41 | - '%s::getTemplateName() must return a string template name, %s value returned', |
|
42 | - $view_class, |
|
43 | - is_object($template) ? get_class($template) : gettype($template) |
|
44 | - ) |
|
45 | - ); |
|
46 | - } |
|
31 | + /** |
|
32 | + * @param string $view_class |
|
33 | + * @param string $template |
|
34 | + * |
|
35 | + * @return static |
|
36 | + */ |
|
37 | + public static function forNonStringValue($view_class, $template) |
|
38 | + { |
|
39 | + return new static( |
|
40 | + sprintf( |
|
41 | + '%s::getTemplateName() must return a string template name, %s value returned', |
|
42 | + $view_class, |
|
43 | + is_object($template) ? get_class($template) : gettype($template) |
|
44 | + ) |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
@@ -12,21 +12,21 @@ |
||
12 | 12 | |
13 | 13 | class StaticPageContentView extends AbstractPageContentView implements TemplateSpecifyingViewModel |
14 | 14 | { |
15 | - protected $variables = [ |
|
16 | - 'page_path' => NULL, |
|
17 | - ]; |
|
15 | + protected $variables = [ |
|
16 | + 'page_path' => NULL, |
|
17 | + ]; |
|
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - */ |
|
22 | - public function getTemplateName() |
|
23 | - { |
|
24 | - if ( ! $this->variables['page_path']) { |
|
25 | - throw UnassignedViewVarException::forVariable(static::class, 'page_path', 'name/of/view'); |
|
26 | - } |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + */ |
|
22 | + public function getTemplateName() |
|
23 | + { |
|
24 | + if ( ! $this->variables['page_path']) { |
|
25 | + throw UnassignedViewVarException::forVariable(static::class, 'page_path', 'name/of/view'); |
|
26 | + } |
|
27 | 27 | |
28 | - return $this->variables['page_path']; |
|
29 | - } |
|
28 | + return $this->variables['page_path']; |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | } |
@@ -22,55 +22,55 @@ |
||
22 | 22 | class ViewTemplateSelector |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @param ViewModel $view |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function getTemplateName(ViewModel $view) |
|
31 | - { |
|
32 | - if ($view instanceof TemplateSpecifyingViewModel) { |
|
33 | - return $this->validateSpecifiedTemplateName($view); |
|
34 | - } else { |
|
35 | - return $this->calculateTemplateFromClassName($view); |
|
36 | - } |
|
37 | - } |
|
25 | + /** |
|
26 | + * @param ViewModel $view |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function getTemplateName(ViewModel $view) |
|
31 | + { |
|
32 | + if ($view instanceof TemplateSpecifyingViewModel) { |
|
33 | + return $this->validateSpecifiedTemplateName($view); |
|
34 | + } else { |
|
35 | + return $this->calculateTemplateFromClassName($view); |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param TemplateSpecifyingViewModel $view |
|
41 | - * |
|
42 | - * @return mixed |
|
43 | - * @throws \UnexpectedValueException if no template is provided |
|
44 | - */ |
|
45 | - protected function validateSpecifiedTemplateName(TemplateSpecifyingViewModel $view) |
|
46 | - { |
|
47 | - $template = $view->getTemplateName(); |
|
48 | - $view_class = get_class($view); |
|
49 | - if ( ! $template) { |
|
50 | - throw UnspecifiedTemplateNameException::forEmptyValue($view_class); |
|
51 | - } |
|
39 | + /** |
|
40 | + * @param TemplateSpecifyingViewModel $view |
|
41 | + * |
|
42 | + * @return mixed |
|
43 | + * @throws \UnexpectedValueException if no template is provided |
|
44 | + */ |
|
45 | + protected function validateSpecifiedTemplateName(TemplateSpecifyingViewModel $view) |
|
46 | + { |
|
47 | + $template = $view->getTemplateName(); |
|
48 | + $view_class = get_class($view); |
|
49 | + if ( ! $template) { |
|
50 | + throw UnspecifiedTemplateNameException::forEmptyValue($view_class); |
|
51 | + } |
|
52 | 52 | |
53 | - if ( ! is_string($template)) { |
|
54 | - throw UnspecifiedTemplateNameException::forNonStringValue($view_class, $template); |
|
55 | - } |
|
53 | + if ( ! is_string($template)) { |
|
54 | + throw UnspecifiedTemplateNameException::forNonStringValue($view_class, $template); |
|
55 | + } |
|
56 | 56 | |
57 | - return $template; |
|
58 | - } |
|
57 | + return $template; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param ViewModel $view |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - protected function calculateTemplateFromClassName(ViewModel $view) |
|
66 | - { |
|
67 | - $template = get_class($view); |
|
68 | - $template = preg_replace('/\\\\|_/', '/', $template); |
|
69 | - $template = preg_replace('#(^view/?(model)?/)|(?<!/)(view/?(model)?$)#i', '', $template); |
|
70 | - $template = preg_replace('/([a-z])([A-Z])/', '\1_\2', $template); |
|
71 | - $template = strtolower($template); |
|
60 | + /** |
|
61 | + * @param ViewModel $view |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + protected function calculateTemplateFromClassName(ViewModel $view) |
|
66 | + { |
|
67 | + $template = get_class($view); |
|
68 | + $template = preg_replace('/\\\\|_/', '/', $template); |
|
69 | + $template = preg_replace('#(^view/?(model)?/)|(?<!/)(view/?(model)?$)#i', '', $template); |
|
70 | + $template = preg_replace('/([a-z])([A-Z])/', '\1_\2', $template); |
|
71 | + $template = strtolower($template); |
|
72 | 72 | |
73 | - return $template; |
|
74 | - } |
|
73 | + return $template; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Configuration for the KohanaView module |
|
4 | - * |
|
5 | - * @author Andrew Coulton <[email protected]> |
|
6 | - * @copyright 2015 inGenerator Ltd |
|
7 | - * @license http://kohanaframework.org/license |
|
8 | - */ |
|
3 | + * Configuration for the KohanaView module |
|
4 | + * |
|
5 | + * @author Andrew Coulton <[email protected]> |
|
6 | + * @copyright 2015 inGenerator Ltd |
|
7 | + * @license http://kohanaframework.org/license |
|
8 | + */ |
|
9 | 9 | return [ |
10 | - 'template_manager' => [ |
|
11 | - // Where compiled templates should be stored |
|
12 | - 'cache_dir' => \Kohana::$cache_dir.'/compiled_templates', |
|
10 | + 'template_manager' => [ |
|
11 | + // Where compiled templates should be stored |
|
12 | + 'cache_dir' => \Kohana::$cache_dir.'/compiled_templates', |
|
13 | 13 | |
14 | - // Whether to recompile all templates on the first use of that template even if it exists |
|
15 | - 'recompile_always' => (\Kohana::$environment === \Kohana::DEVELOPMENT), |
|
16 | - ], |
|
14 | + // Whether to recompile all templates on the first use of that template even if it exists |
|
15 | + 'recompile_always' => (\Kohana::$environment === \Kohana::DEVELOPMENT), |
|
16 | + ], |
|
17 | 17 | ]; |