Completed
Pull Request — 2.0.x (#6)
by Andrew
02:09
created
koharness.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,6 +8,6 @@
 block discarded – undo
8 8
  */
9 9
 return array(
10 10
   'modules' => array(
11
-    'kohana-view' => __DIR__,
11
+	'kohana-view' => __DIR__,
12 12
   )
13 13
 );
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/ViewTemplateSelector.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -18,61 +18,61 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/ViewModel.php 1 patch
Indentation   +9 added lines, -9 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;
9 9
 
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 interface ViewModel
18 18
 {
19 19
 
20
-    /**
21
-     * @param  array $variables
22
-     * @return void
23
-     */
24
-    public function display(array $variables);
20
+	/**
21
+	 * @param  array $variables
22
+	 * @return void
23
+	 */
24
+	public function display(array $variables);
25 25
 
26 26
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/ViewModel/AbstractViewModel.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -37,81 +37,81 @@
 block discarded – undo
37 37
  */
38 38
 abstract class AbstractViewModel implements ViewModel
39 39
 {
40
-    /**
41
-     * @var array The actual view data
42
-     */
43
-    protected $variables = [];
40
+	/**
41
+	 * @var array The actual view data
42
+	 */
43
+	protected $variables = [];
44 44
 
45
-    /**
46
-     * @var string[] The names of the valid set of fields that must be passed to the display() method
47
-     */
48
-    protected $expect_var_names = [];
45
+	/**
46
+	 * @var string[] The names of the valid set of fields that must be passed to the display() method
47
+	 */
48
+	protected $expect_var_names = [];
49 49
 
50
-    public function __construct()
51
-    {
52
-        // Assign the expect_var_names to ensure that we don't accidentally start requiring compiled fields
53
-        $this->expect_var_names = array_keys($this->variables);
54
-    }
50
+	public function __construct()
51
+	{
52
+		// Assign the expect_var_names to ensure that we don't accidentally start requiring compiled fields
53
+		$this->expect_var_names = array_keys($this->variables);
54
+	}
55 55
 
56
-    /**
57
-     * Get field values
58
-     *
59
-     * @param string $name
60
-     *
61
-     * @return mixed
62
-     */
63
-    public function __get($name)
64
-    {
65
-        if (array_key_exists($name, $this->variables)) {
66
-            return $this->variables[$name];
67
-        } elseif (method_exists($this, 'var_'.$name)) {
68
-            $method = 'var_'.$name;
56
+	/**
57
+	 * Get field values
58
+	 *
59
+	 * @param string $name
60
+	 *
61
+	 * @return mixed
62
+	 */
63
+	public function __get($name)
64
+	{
65
+		if (array_key_exists($name, $this->variables)) {
66
+			return $this->variables[$name];
67
+		} elseif (method_exists($this, 'var_'.$name)) {
68
+			$method = 'var_'.$name;
69 69
 
70
-            return $this->$method();
71
-        } else {
72
-            throw new \BadMethodCallException(static::class." does not define a '$name' field");
73
-        }
74
-    }
70
+			return $this->$method();
71
+		} else {
72
+			throw new \BadMethodCallException(static::class." does not define a '$name' field");
73
+		}
74
+	}
75 75
 
76
-    /**
77
-     * @param string $name
78
-     * @param mixed  $value
79
-     *
80
-     * @throws \BadMethodCallException values cannot be assigned except with the display method
81
-     */
82
-    public function __set($name, $value)
83
-    {
84
-        throw new \BadMethodCallException(static::class.' variables are read-only, cannot assign '.$name);
85
-    }
76
+	/**
77
+	 * @param string $name
78
+	 * @param mixed  $value
79
+	 *
80
+	 * @throws \BadMethodCallException values cannot be assigned except with the display method
81
+	 */
82
+	public function __set($name, $value)
83
+	{
84
+		throw new \BadMethodCallException(static::class.' variables are read-only, cannot assign '.$name);
85
+	}
86 86
 
87
-    /**
88
-     * Set the data to be rendered in the view - note this does not actually render the view.
89
-     *
90
-     * @param array $variables
91
-     */
92
-    public function display(array $variables)
93
-    {
94
-        $errors             = [];
95
-        $provided_variables = array_keys($variables);
96
-        foreach (array_diff($provided_variables, $this->expect_var_names) as $unexpected_var) {
97
-            if (method_exists($this, 'var_'.$unexpected_var)) {
98
-                $errors[] = "'$unexpected_var' conflicts with ::var_$unexpected_var()";
99
-            } else {
100
-                $errors[] = "'$unexpected_var' is not expected";
101
-            }
102
-        }
103
-        foreach (array_diff($this->expect_var_names, $provided_variables) as $missing_var) {
104
-            $errors[] = "'$missing_var' is missing";
105
-        }
87
+	/**
88
+	 * Set the data to be rendered in the view - note this does not actually render the view.
89
+	 *
90
+	 * @param array $variables
91
+	 */
92
+	public function display(array $variables)
93
+	{
94
+		$errors             = [];
95
+		$provided_variables = array_keys($variables);
96
+		foreach (array_diff($provided_variables, $this->expect_var_names) as $unexpected_var) {
97
+			if (method_exists($this, 'var_'.$unexpected_var)) {
98
+				$errors[] = "'$unexpected_var' conflicts with ::var_$unexpected_var()";
99
+			} else {
100
+				$errors[] = "'$unexpected_var' is not expected";
101
+			}
102
+		}
103
+		foreach (array_diff($this->expect_var_names, $provided_variables) as $missing_var) {
104
+			$errors[] = "'$missing_var' is missing";
105
+		}
106 106
 
107
-        if ( ! empty($errors)) {
108
-            throw new \InvalidArgumentException(
109
-                "Invalid variables provided to ".static::class."::display()"
110
-                ."\n - ".implode("\n - ", $errors)
111
-            );
112
-        }
107
+		if ( ! empty($errors)) {
108
+			throw new \InvalidArgumentException(
109
+				"Invalid variables provided to ".static::class."::display()"
110
+				."\n - ".implode("\n - ", $errors)
111
+			);
112
+		}
113 113
 
114
-        $this->variables = $variables;
115
-    }
114
+		$this->variables = $variables;
115
+	}
116 116
 
117 117
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/TemplateCompiler.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -31,86 +31,86 @@
 block discarded – undo
31 31
 class TemplateCompiler
32 32
 {
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    protected $options = [
38
-        'raw_output_prefix' => '!',
39
-        'escape_method'     => 'HTML::chars',
40
-    ];
34
+	/**
35
+	 * @var array
36
+	 */
37
+	protected $options = [
38
+		'raw_output_prefix' => '!',
39
+		'escape_method'     => 'HTML::chars',
40
+	];
41 41
 
42
-    /**
43
-     * @param array $options
44
-     */
45
-    public function __construct(array $options = [])
46
-    {
47
-        $this->options = array_merge($this->options, $options);
48
-    }
42
+	/**
43
+	 * @param array $options
44
+	 */
45
+	public function __construct(array $options = [])
46
+	{
47
+		$this->options = array_merge($this->options, $options);
48
+	}
49 49
 
50
-    /**
51
-     * Compile a string containing a PHP template, automatically escaping variables that are echoed in PHP short tags,
52
-     * and return the compiled PHP string.
53
-     *
54
-     * @param string $source
55
-     *
56
-     * @return string
57
-     * @throws \InvalidArgumentException if the template is empty or invalid
58
-     */
59
-    public function compile($source)
60
-    {
61
-        if ( ! $source) {
62
-            throw new \InvalidArgumentException('Cannot compile empty template');
63
-        }
50
+	/**
51
+	 * Compile a string containing a PHP template, automatically escaping variables that are echoed in PHP short tags,
52
+	 * and return the compiled PHP string.
53
+	 *
54
+	 * @param string $source
55
+	 *
56
+	 * @return string
57
+	 * @throws \InvalidArgumentException if the template is empty or invalid
58
+	 */
59
+	public function compile($source)
60
+	{
61
+		if ( ! $source) {
62
+			throw new \InvalidArgumentException('Cannot compile empty template');
63
+		}
64 64
 
65
-        return preg_replace_callback('/<\?=(.+?)(;|\?>)/s', [$this, 'compilePhpShortTag'], $source);
66
-    }
65
+		return preg_replace_callback('/<\?=(.+?)(;|\?>)/s', [$this, 'compilePhpShortTag'], $source);
66
+	}
67 67
 
68
-    /**
69
-     * @param string[] $matches
70
-     *
71
-     * @return string
72
-     */
73
-    protected function compilePhpShortTag($matches)
74
-    {
75
-        $var               = trim($matches[1]);
76
-        $terminator        = $matches[2];
77
-        $escape_method     = $this->options['escape_method'];
78
-        $raw_output_prefix = $this->options['raw_output_prefix'];
68
+	/**
69
+	 * @param string[] $matches
70
+	 *
71
+	 * @return string
72
+	 */
73
+	protected function compilePhpShortTag($matches)
74
+	{
75
+		$var               = trim($matches[1]);
76
+		$terminator        = $matches[2];
77
+		$escape_method     = $this->options['escape_method'];
78
+		$raw_output_prefix = $this->options['raw_output_prefix'];
79 79
 
80
-        if ($this->startsWith($var, $raw_output_prefix)) {
81
-            // Remove prefix and echo unescaped
82
-            $compiled = '<?='.trim(substr($var, strlen($raw_output_prefix))).';';
83
-        } elseif ($this->startsWith($var, '//')) {
84
-            // Echo an empty string to prevent the comment causing a parse error
85
-            $compiled = "<?='';$var;";
80
+		if ($this->startsWith($var, $raw_output_prefix)) {
81
+			// Remove prefix and echo unescaped
82
+			$compiled = '<?='.trim(substr($var, strlen($raw_output_prefix))).';';
83
+		} elseif ($this->startsWith($var, '//')) {
84
+			// Echo an empty string to prevent the comment causing a parse error
85
+			$compiled = "<?='';$var;";
86 86
 
87
-        } elseif ($this->startsWith($var, $escape_method)) {
88
-            // Try to help user to avoid accidental double-escaping
89
-            throw new \InvalidArgumentException(
90
-                "Invalid implicit double-escape in template - remove $escape_method from {$matches[0]} or mark as raw"
91
-            );
87
+		} elseif ($this->startsWith($var, $escape_method)) {
88
+			// Try to help user to avoid accidental double-escaping
89
+			throw new \InvalidArgumentException(
90
+				"Invalid implicit double-escape in template - remove $escape_method from {$matches[0]} or mark as raw"
91
+			);
92 92
 
93
-        } else {
94
-            // Escape the value before echoing
95
-            $compiled = "<?={$escape_method}($var);";
96
-        }
93
+		} else {
94
+			// Escape the value before echoing
95
+			$compiled = "<?={$escape_method}($var);";
96
+		}
97 97
 
98
-        if ($terminator === '?>') {
99
-            $compiled .= '?>';
100
-        }
98
+		if ($terminator === '?>') {
99
+			$compiled .= '?>';
100
+		}
101 101
 
102
-        return $compiled;
103
-    }
102
+		return $compiled;
103
+	}
104 104
 
105
-    /**
106
-     * @param string $string
107
-     * @param string $prefix
108
-     *
109
-     * @return bool
110
-     */
111
-    protected function startsWith($string, $prefix)
112
-    {
113
-        return (strncmp($string, $prefix, strlen($prefix)) === 0);
114
-    }
105
+	/**
106
+	 * @param string $string
107
+	 * @param string $prefix
108
+	 *
109
+	 * @return bool
110
+	 */
111
+	protected function startsWith($string, $prefix)
112
+	{
113
+		return (strncmp($string, $prefix, strlen($prefix)) === 0);
114
+	}
115 115
 
116 116
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/TemplateManager.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/TemplateManager/CFSWrapper.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,11 +15,11 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/TemplateSpecifyingViewModel.php 1 patch
Indentation   +8 added lines, -8 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;
9 9
 
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
classes/Ingenerator/KohanaView/Renderer.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.