diff options
author | Daniel Weipert <code@drogueronin.de> | 2021-04-20 12:44:20 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2021-04-20 12:44:20 +0200 |
commit | 11dc8c730dda2c5bd38cb386f96331c5ce3cac9c (patch) | |
tree | b2c03112114af00e33ce8e1276194906064fcf93 /src/TemplateModule.php | |
parent | d4d5ae3bb6566311b2d42cf888e463b62f6cf0dc (diff) |
Adds a bunch of new Modules
Diffstat (limited to 'src/TemplateModule.php')
-rw-r--r-- | src/TemplateModule.php | 42 |
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 []; + } +} |