1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Utilise Mercurial from within Phing. |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.4 |
6
|
|
|
* |
7
|
|
|
* @category Tasks |
8
|
|
|
* @package phing.tasks.ext |
9
|
|
|
* @author Ken Guest <[email protected]> |
10
|
|
|
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html) |
11
|
|
|
* @link https://github.com/kenguest/Phing-HG |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base task for integrating phing and mercurial. |
16
|
|
|
* |
17
|
|
|
* @category Tasks |
18
|
|
|
* @package phing.tasks.ext.hg |
19
|
|
|
* @author Ken Guest <[email protected]> |
20
|
|
|
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html) |
21
|
|
|
* @link HgBaseTask.php |
22
|
|
|
*/ |
23
|
|
|
abstract class HgBaseTask extends Task |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Insecure argument |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $insecure = ''; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Repository directory |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $repository = ''; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Whether to be quiet... --quiet argument. |
41
|
|
|
* |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
protected $quiet = false; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Username. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $user = ''; |
52
|
|
|
|
53
|
|
|
public static $factory = null; |
54
|
|
|
/** |
55
|
|
|
* Set repository attribute |
56
|
|
|
* |
57
|
|
|
* @param string $repository Repository |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
16 |
|
public function setRepository($repository) |
62
|
|
|
{ |
63
|
16 |
|
$this->repository = $repository; |
64
|
16 |
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set the quiet attribute --quiet |
69
|
|
|
* |
70
|
|
|
* @param string $quiet yes|no|true|false|1|0 |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
public function setQuiet($quiet) |
75
|
|
|
{ |
76
|
|
|
$this->quiet = StringHelper::booleanValue($quiet); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the quiet attribute value. |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
15 |
|
public function getQuiet() |
85
|
|
|
{ |
86
|
15 |
|
return $this->quiet; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get Repository attribute/directory. |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
3 |
|
public function getRepository() |
95
|
|
|
{ |
96
|
3 |
|
return $this->repository; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set insecure attribute |
101
|
|
|
* |
102
|
|
|
* @param string $insecure 'yes', etc. |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
*/ |
106
|
|
|
public function setInsecure($insecure) |
107
|
|
|
{ |
108
|
|
|
$this->insecure = StringHelper::booleanValue($insecure); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get 'insecure' attribute value. (--insecure or null) |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
11 |
|
public function getInsecure() |
117
|
|
|
{ |
118
|
11 |
|
return $this->insecure; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set user attribute |
123
|
|
|
* |
124
|
|
|
* @param string $user username/email address. |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
2 |
|
public function setUser($user) |
129
|
|
|
{ |
130
|
2 |
|
$this->user = $user; |
131
|
2 |
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get username attribute. |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
1 |
|
public function getUser() |
139
|
|
|
{ |
140
|
1 |
|
return $this->user; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Check provided repository directory actually is an existing directory. |
145
|
|
|
* |
146
|
|
|
* @param string $dir Repository directory |
147
|
|
|
* |
148
|
|
|
* @return bool |
149
|
|
|
* @throws BuildException |
150
|
|
|
*/ |
151
|
11 |
|
public function checkRepositoryIsDirAndExists($dir) |
152
|
|
|
{ |
153
|
11 |
|
if (file_exists($dir)) { |
154
|
7 |
|
if (!is_dir($dir)) { |
155
|
7 |
|
throw new BuildException("Repository '$dir' is not a directory."); |
156
|
|
|
} |
157
|
|
|
} else { |
158
|
4 |
|
throw new BuildException("Repository directory '$dir' does not exist."); |
159
|
|
|
} |
160
|
7 |
|
return true; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Initialise the task. |
165
|
|
|
* |
166
|
|
|
* @return void |
167
|
|
|
*/ |
168
|
22 |
|
public function init() |
169
|
|
|
{ |
170
|
22 |
|
@include_once 'vendor/autoload.php'; |
171
|
22 |
|
} |
172
|
|
|
|
173
|
21 |
|
public function getFactoryInstance($command, $options = []) |
174
|
|
|
{ |
175
|
21 |
|
$vchq = '\\Siad007\\VersionControl\\HG\\Factory'; |
176
|
21 |
|
self::$factory = $vchq::getInstance($command, $options); |
177
|
21 |
|
return self::$factory; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.