Test Failed
Push — master ( c3ea58...eb5801 )
by Jean-Christophe
13:07
created

SimpleViewController::_includeFileAsString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 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
	public function __construct() {
17
	}
18
19
	protected function _includeFileAsString($filename, $pData) {
20
		if (isset ( $pData )) {
21
			\extract ( $pData );
22
		}
23
		\ob_start ();
24
		include ($filename);
25
		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
	public function loadView($viewName, $pData = NULL, $asString = false) {
40
		$filename = \ROOT . \DS . 'views' . \DS . $viewName;
41
		if ($asString) {
42
			return $this->_includeFileAsString ( $filename, $pData );
43
		}
44
		if (isset ( $pData )) {
45
			\extract ( $pData );
46
		}
47
		include ($filename);
48
	}
49
}
50