Completed
Pull Request — 2.0.x (#6)
by Andrew
02:11
created
classes/Ingenerator/KohanaView/Renderer/PageLayoutRenderer.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -34,82 +34,82 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Ingenerator/KohanaView/Exception/InvalidDisplayVariablesException.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,20 +16,20 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Ingenerator/KohanaView/Exception/InvalidViewVarAssignmentException.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/Exception/TemplateCacheException.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/Exception/TemplateNotFoundException.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -15,27 +15,27 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/Exception/UnassignedViewVarException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Ingenerator/KohanaView/Exception/UnspecifiedTemplateNameException.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Ingenerator/KohanaView/ViewModel/PageLayout/StaticPageContentView.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/ViewTemplateSelector.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -22,55 +22,55 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.