1 | <?php declare(strict_types=1); |
||
13 | class Script |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $directory; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $scriptName; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $environment; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | public $description; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $isHiddenPath; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $workingDirectory; |
||
44 | |||
45 | public function __construct( |
||
46 | string $directory, |
||
47 | string $scriptName, |
||
48 | bool $isHiddenPath, |
||
49 | string $workingDirectory, |
||
50 | ?string $environment = null, |
||
51 | string $description = '' |
||
52 | ) { |
||
53 | $this->directory = $directory; |
||
54 | $this->scriptName = $scriptName; |
||
55 | $this->environment = $environment; |
||
56 | $this->description = $description; |
||
57 | $this->isHiddenPath = $isHiddenPath; |
||
58 | $this->workingDirectory = $workingDirectory; |
||
59 | } |
||
60 | |||
61 | public function getTmpPath(): string |
||
62 | { |
||
63 | return sprintf('%s/.tmp_%s_%s', $this->directory, getmypid(), $this->scriptName); |
||
64 | } |
||
65 | |||
66 | public function getPath(): string |
||
67 | { |
||
68 | return $this->directory . '/' . $this->scriptName; |
||
69 | } |
||
70 | |||
71 | public function getDirectory(): string |
||
72 | { |
||
73 | return $this->directory; |
||
74 | } |
||
75 | |||
76 | public function getName(): string |
||
77 | { |
||
78 | $name = pathinfo($this->scriptName, PATHINFO_FILENAME); |
||
79 | |||
80 | if (!$this->environment) { |
||
81 | return $name; |
||
82 | } |
||
83 | |||
84 | return $this->environment . ':' . $name; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return string|null |
||
89 | */ |
||
90 | public function getEnvironment() |
||
91 | { |
||
92 | return $this->environment; |
||
93 | } |
||
94 | |||
95 | public function getDescription(): string |
||
99 | |||
100 | public function isHidden(): bool |
||
101 | { |
||
102 | return $this->isHiddenPath || mb_strpos($this->scriptName, '.') === 0; |
||
103 | } |
||
104 | |||
105 | public function getWorkingDirectory(): string |
||
106 | { |
||
109 | } |
||
110 |