1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Shopware\Psh\Listing; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* ValueObject containing all information for a single script to be executed |
8
|
|
|
*/ |
9
|
|
|
class Script |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $directory; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $scriptName; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $environment; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $description; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
private $inHiddenPath; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $directory |
38
|
|
|
* @param string $scriptName |
39
|
|
|
* @param bool $inHiddenPath |
40
|
|
|
* @param string $environment |
41
|
|
|
* @param string $description |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
string $directory, |
45
|
|
|
string $scriptName, |
46
|
|
|
bool $inHiddenPath, |
47
|
|
|
string $environment = null, |
48
|
|
|
$description = '' |
49
|
|
|
) { |
50
|
|
|
$this->directory = $directory; |
51
|
|
|
$this->scriptName = $scriptName; |
52
|
|
|
$this->environment = $environment; |
53
|
|
|
$this->description = $description; |
54
|
|
|
$this->inHiddenPath = $inHiddenPath; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getTmpPath(): string |
61
|
|
|
{ |
62
|
|
|
return $this->directory . '/.tmp_' . getmypid() . '_' . $this->scriptName; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getPath(): string |
70
|
|
|
{ |
71
|
|
|
return $this->directory . '/' . $this->scriptName; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getDirectory(): string |
78
|
|
|
{ |
79
|
|
|
return $this->directory; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getName(): string |
86
|
|
|
{ |
87
|
|
|
$name = pathinfo($this->scriptName, PATHINFO_FILENAME); |
88
|
|
|
|
89
|
|
|
if (!$this->environment) { |
90
|
|
|
return $name; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->environment . ':' . $name; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return string|null |
98
|
|
|
*/ |
99
|
|
|
public function getEnvironment() |
100
|
|
|
{ |
101
|
|
|
return $this->environment; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
public function getDescription(): string |
108
|
|
|
{ |
109
|
|
|
return $this->description; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
public function isHidden(): bool |
116
|
|
|
{ |
117
|
|
|
return $this->inHiddenPath || strpos($this->scriptName, '.') === 0; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|