Passed
Push — master ( 491b2f...f3582b )
by Jean-Christophe
09:33
created

SimpleViewController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 2
b 0
f 0
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A loadView() 0 9 3
A _includeFileAsString() 0 7 2
1
<?php
2
3
namespace Ubiquity\controllers;
4
5
/**
6
 * Default controller displaying php views only.
7
 * Ubiquity\controllers$ControllerView
8
 * This class is part of Ubiquity
9
 *
10
 * @author jcheron <[email protected]>
11
 * @version 1.0.0
12
 *
13
 */
14
abstract class SimpleViewController extends Controller {
15
16 4
	public function __construct() {
17 4
	}
18
19 1
	protected function _includeFileAsString($filename, $pData) {
20 1
		if (isset ( $pData )) {
21 1
			\extract ( $pData );
22
		}
23 1
		\ob_start ();
24 1
		include ($filename);
25 1
		return \ob_get_clean ();
26
	}
27
28
	/**
29
	 * Loads the php view $viewName possibly passing the variables $pdata
30
	 *
31
	 * @param string $viewName The name of the view to load
32
	 * @param mixed $pData Variable or associative array to pass to the view
33
	 *        If a variable is passed, it will have the name **$data** in the view,
34
	 *        If an associative array is passed, the view retrieves variables from the table's key names
35
	 * @param boolean $asString If true, the view is not displayed but returned as a string (usable in a variable)
36
	 * @throws \Exception
37
	 * @return string null or the view content if **$asString** parameter is true
38
	 */
39 2
	public function loadView($viewName, $pData = NULL, $asString = false) {
40 2
		$filename = \ROOT . \DS . 'views' . \DS . $viewName;
41 2
		if ($asString) {
42 1
			return $this->_includeFileAsString ( $filename, $pData );
43
		}
44 1
		if (isset ( $pData )) {
45 1
			\extract ( $pData );
46
		}
47 1
		include ($filename);
48 1
	}
49
}
50