summaryrefslogtreecommitdiff
path: root/src/Support/Permissions.php
blob: daabf5adee7cd6e24f62203dab93242735f36766 (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
<?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);
    }
}