Passed
Push — master ( 794fa7...a398e6 )
by Atanas
01:57
created

Php::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\Templating;
4
5
/**
6
 * Include template files with php
7
 */
8
class Php implements EngineInterface {
9
	/**
10
	 * Global context
11
	 *
12
	 * @var array
13
	 */
14
	protected $global_context = [];
15
16
	/**
17
	 * Constructor
18
	 *
19
	 * @param array $global_context
20
	 */
21 1
	public function __construct( $global_context ) {
22 1
		$this->global_context = $global_context;
23 1
	}
24
25
	/**
26
	 * {@inheritDoc}
27
	 */
28 3
	public function render( $file, $context ) {
29 3
		$__template = $file;
30 3
		$__context = array_merge(
31 3
			['global' => $this->global_context],
32
			$context
33 3
		);
34 3
		$renderer = function() use ( $__template, $__context ) {
35 3
			ob_start();
36 3
			extract( $__context );
37 3
			include( $__template );
38 3
			return ob_get_clean();
39 3
		};
40 3
		return $renderer();
41
	}
42
}
43