summaryrefslogtreecommitdiff
path: root/src/TemplateModule.php
blob: 515d891d3e1677ef2bacef1f16bb947548b3dcf5 (plain)
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
39
40
41
42
<?php

namespace PHPIAC\Modules;

use PHPIAC\Connection;
use PHPIAC\Module\Module;
use PHPIAC\Modules\Support\HasPermissions;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

class TemplateModule extends Module
{
    use HasPermissions;

    protected string $src;
    protected string $dest;
    protected array $vars;

    /**
     * @inheritDoc
     */
    public function checkState(): bool
    {
        return false;
    }

    /**
     * @inheritDoc
     */
    public function getCommands(): array
    {
        $loader = new FilesystemLoader(dirname($this->src));
        $twig = new Environment($loader);
        $rendered = $twig->render(basename($this->src), $this->vars);

        Connection::put($this->dest, $rendered);

        Connection::exec($this->getPermissions($this->dest));

        return [];
    }
}