-
Notifications
You must be signed in to change notification settings - Fork 2
/
View.php
38 lines (33 loc) · 942 Bytes
/
View.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace bashkarev\swiftmailer;
/**
* @author Dmitriy Bashkarev <[email protected]>
*/
class View
{
/**
* @param $view
* @param array $params
* @param null $context
* @return string
*/
public function render($view, $params = [], $context = null)
{
$viewFile = $context->getViewPath() . '/' . $view . '.php';
return $this->renderPhpFile($viewFile, $params, $context);
}
/**
* Renders a view file as a PHP script.
* @param string $_file_ the view file.
* @param array $_params_ the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return string the rendering result
*/
public function renderPhpFile($_file_, $_params_ = [])
{
ob_start();
ob_implicit_flush(false);
extract($_params_, EXTR_OVERWRITE);
require($_file_);
return ob_get_clean();
}
}