Test Setup Failed
Pull Request — master (#216)
by Maximo
04:19
created

Template::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas;
6
7
use Canvas\Models\EmailTemplates;
8
use Phalcon\Di;
9
use Phalcon\Di\Injectable;
10
11
/**
12
 * Class Validation.
13
 *
14
 * @package Canvas
15
 */
16
class Template
17
{
18
    /**
19
     * Given the email tempalte name and its params
20
     *  - create the files
21
     *  - render it with the variables
22
     *  - return the content string for use to use anywhere.
23
     *
24
     * @param string $name
25
     * @param array $params
26
     * @return string
27
     */
28
    public static function generate(string $name, array $params): string
29
    {
30
        $di = Di::getDefault();
31
        $view = $di->getView();
32
        $filesystem = $di->get('filesystem', ['local']);
33
34
        //get the teamplate
35
        $template = EmailTemplates::getByName($name);
36
        $file = $template->name . '.volt';
37
        
38
        //write file
39
        $filesystem->put('/view/'.$file, $template->template);
40
41
        //rendre and return content
42
        return $view->render($template->name, $params);
43
    }
44
}
45