1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Onigoetz\Deployer\Configuration\Sources; |
4
|
|
|
|
5
|
|
|
use Onigoetz\Deployer\Configuration\Source; |
6
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Question\Question; |
10
|
|
|
|
11
|
|
|
//the name of the class is "cloned" as "clone" is a reserved keyword |
12
|
|
|
class Cloned extends Source |
13
|
|
|
{ |
14
|
|
|
public static $defaultType = 'git'; |
15
|
|
|
public static $defaultBranch = 'master'; |
16
|
6 |
|
public static $defaultSubmodules = false; |
17
|
|
|
|
18
|
6 |
|
public function getType() |
19
|
|
|
{ |
20
|
|
|
return $this->getValueOrDefault('type', self::$defaultType); |
21
|
18 |
|
} |
22
|
|
|
|
23
|
18 |
|
public function getBranch() |
24
|
|
|
{ |
25
|
|
|
return $this->getValueOrDefault('branch', self::$defaultBranch); |
26
|
6 |
|
} |
27
|
|
|
|
28
|
6 |
|
public function getSubmodules() |
29
|
|
|
{ |
30
|
|
|
return $this->getValueOrDefault('submodules', self::$defaultSubmodules); |
31
|
18 |
|
} |
32
|
|
|
|
33
|
18 |
|
public function getUsername() |
34
|
|
|
{ |
35
|
|
|
return $this->getValueOrDefault('username', null); |
36
|
3 |
|
} |
37
|
|
|
|
38
|
3 |
|
public function setUsername($username) |
39
|
3 |
|
{ |
40
|
|
|
$this->data['username'] = $username; |
41
|
21 |
|
} |
42
|
|
|
|
43
|
21 |
|
public function getPassword() |
44
|
|
|
{ |
45
|
|
|
return $this->getValueOrDefault('password', null); |
46
|
9 |
|
} |
47
|
|
|
|
48
|
9 |
|
public function setPassword($password) |
49
|
9 |
|
{ |
50
|
|
|
$this->data['password'] = $password; |
51
|
18 |
|
} |
52
|
|
|
|
53
|
18 |
|
public function getFinalUrl(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output) |
54
|
18 |
|
{ |
55
|
|
|
$regex = '/^((?P<scheme>https?):\\/)?\\/?((?P<username>.*?)(:(?P<password>.*?)|)@)?(?P<uri>.*)/'; |
56
|
|
|
preg_match($regex, $this->getPath(), $matches); |
57
|
18 |
|
|
58
|
6 |
|
//username provided ? |
59
|
16 |
|
if ($matches['username']) { |
60
|
3 |
|
$username = $matches['username']; |
61
|
3 |
|
} elseif (!$username = $this->getUsername()) { |
62
|
2 |
|
$question = new Question('What is the repository username?'); |
63
|
|
|
$username = $questionHelper->ask($input, $output, $question); |
64
|
|
|
$this->setUsername($username); |
65
|
18 |
|
} |
66
|
3 |
|
|
67
|
17 |
|
//password provided ? |
68
|
9 |
|
if ($matches['password']) { |
69
|
9 |
|
$password = $matches['password']; |
70
|
6 |
|
} elseif (!$password = $this->getPassword()) { |
71
|
|
|
$question = new Question('What is the repository password?', false); |
72
|
|
|
$question->setHidden(true)->setHiddenFallback(false); |
73
|
18 |
|
$password = $questionHelper->ask($input, $output, $question); |
74
|
|
|
$this->setPassword($password); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
//HTTP(S)? username:password@ |
78
|
|
|
return "{$matches['scheme']}://$username:$password@{$matches['uri']}"; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|