Completed
Push — master ( 8f1053...c250e4 )
by Antonio
13:19
created

PhpViewFileHelper::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6667
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
namespace Da\Mailer\Helper;
3
4
final class PhpViewFileHelper
5
{
6
    /**
7
     * Renders a view file as a PHP script.
8
     *
9
     * This method expects a php file and includes the file after it extracts the given parameters (name-value pairs)
10
     * to make them available to the php file. Captures the output and returns its result as a string.
11
     *
12
     * @param string $file full path of the view file
13
     * @param array $params the parameters that will be extracted and make them available to the php view file.
14
     *
15
     * @return string the rendering result.
16
     */
17
    public static function render($file, array $params = [])
18
    {
19
        ob_start();
20
        ob_implicit_flush(false);
21
        extract($params, EXTR_OVERWRITE);
22
        require($file);
23
24
        return ob_get_clean();
25
    }
26
}
27