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/Support | |
parent | d4d5ae3bb6566311b2d42cf888e463b62f6cf0dc (diff) |
Adds a bunch of new Modules
Diffstat (limited to 'src/Support')
-rw-r--r-- | src/Support/HasPermissions.php | 15 | ||||
-rw-r--r-- | src/Support/Permissions.php | 28 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/Support/HasPermissions.php b/src/Support/HasPermissions.php new file mode 100644 index 0000000..c42d71d --- /dev/null +++ b/src/Support/HasPermissions.php @@ -0,0 +1,15 @@ +<?php + +namespace PHPIAC\Modules\Support; + +trait HasPermissions +{ + protected string $owner = ''; + protected string $group = ''; + protected int $mode = 0; + + public function getPermissions($path): string + { + return new Permissions($path, $this->owner, $this->group, $this->mode); + } +} diff --git a/src/Support/Permissions.php b/src/Support/Permissions.php new file mode 100644 index 0000000..daabf5a --- /dev/null +++ b/src/Support/Permissions.php @@ -0,0 +1,28 @@ +<?php + +namespace PHPIAC\Modules\Support; + +class Permissions +{ + public function __construct( + protected string $path, + protected string $owner = '', + protected string $group = '', + protected int $mode = 0, + ) {} + + public function __toString(): string + { + $permissions = []; + + if (! empty($this->owner) || ! empty($this->group)) { + $permissions[] = "sudo chown -R $this->owner:$this->group $this->path"; + } + + if (! empty($this->mode)) { + $permissions[] = "sudo chmod -R $this->mode $this->path"; + } + + return implode(PHP_EOL, $permissions); + } +} |