summaryrefslogtreecommitdiff
path: root/src/TemplateModule.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/TemplateModule.php')
-rw-r--r--src/TemplateModule.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/TemplateModule.php b/src/TemplateModule.php
new file mode 100644
index 0000000..515d891
--- /dev/null
+++ b/src/TemplateModule.php
@@ -0,0 +1,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 [];
+ }
+}