Passed
Push — master ( bfeba0...b198de )
by Aimeos
06:28 queued 03:22
created

Blade::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2022
6
 * @package MW
7
 * @subpackage View
8
 */
9
10
11
namespace Aimeos\Base\View\Engine;
12
13
14
/**
15
 * Blade view engine implementation
16
 *
17
 * @package MW
18
 * @subpackage View
19
 */
20
class Blade implements Iface
21
{
22
	private $factory;
23
24
25
	/**
26
	 * Initializes the view object
27
	 *
28
	 * @param \Illuminate\View\Factory $factory Laravel view factory
29
	 */
30
	public function __construct( \Illuminate\View\Factory $factory )
31
	{
32
		$this->factory = $factory;
33
	}
34
35
36
	/**
37
	 * Renders the output based on the given template file name and the key/value pairs
38
	 *
39
	 * @param \Aimeos\Base\View\Iface $view View object
40
	 * @param string $filename File name of the view template
41
	 * @param array $values Associative list of key/value pairs
42
	 * @return string Output generated by the template
43
	 * @throws \Aimeos\Base\View\Exception If the template isn't found
44
	 */
45
	public function render( \Aimeos\Base\View\Iface $view, string $filename, array $values ) : string
46
	{
47
		$factory = $this->factory;
48
		$lv = $factory->file( $filename, $values );
49
50
		$fcn = function() use ( $factory, $view )
51
		{
52
			foreach( $factory->getSections() as $name => $section ) {
53
				$view->block()->set( $name, $section );
54
			}
55
		};
56
57
		$contents = $lv->render( $fcn );
58
		$this->factory->flushSections();
59
60
		return $contents;
61
	}
62
}
63