1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Potherca\Flysystem\Github; |
4
|
|
|
|
5
|
|
|
use Github\Client; |
6
|
|
|
|
7
|
|
|
class Settings implements SettingsInterface |
8
|
|
|
{ |
9
|
|
|
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
10
|
|
|
const AUTHENTICATE_USING_TOKEN = Client::AUTH_URL_TOKEN; |
11
|
|
|
const AUTHENTICATE_USING_PASSWORD = Client::AUTH_HTTP_PASSWORD; |
12
|
|
|
|
13
|
|
|
const BRANCH_MASTER = 'master'; |
14
|
|
|
const REFERENCE_HEAD = 'HEAD'; |
15
|
|
|
|
16
|
|
|
const ERROR_INVALID_REPOSITORY_NAME = 'Given Repository name "%s" should be in the format of "vendor/project"'; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
private $branch; |
20
|
|
|
/** @var array */ |
21
|
|
|
private $credentials; |
22
|
|
|
/** @var string */ |
23
|
|
|
private $reference; |
24
|
|
|
/** @var string */ |
25
|
|
|
private $repository; |
26
|
|
|
/** @var string */ |
27
|
|
|
private $vendor; |
28
|
|
|
/** @var string */ |
29
|
|
|
private $package; |
30
|
|
|
|
31
|
|
|
//////////////////////////// SETTERS AND GETTERS \\\\\\\\\\\\\\\\\\\\\\\\\\\ |
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
final public function getBranch() |
36
|
|
|
{ |
37
|
|
|
return $this->branch; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
final public function getCredentials() |
44
|
|
|
{ |
45
|
|
|
return $this->credentials; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
final public function getPackage() |
52
|
|
|
{ |
53
|
|
|
return $this->package; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
final public function getReference() |
60
|
|
|
{ |
61
|
|
|
return $this->reference; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
final public function getRepository() |
68
|
|
|
{ |
69
|
|
|
return $this->repository; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
final public function getVendor() |
76
|
|
|
{ |
77
|
|
|
return $this->vendor; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
81
|
|
|
final public function __construct( |
82
|
|
|
$repository, |
83
|
|
|
array $credentials = [], |
84
|
|
|
$branch = self::BRANCH_MASTER, |
85
|
|
|
$reference = self::REFERENCE_HEAD |
86
|
|
|
) { |
87
|
|
|
$this->isValidRepositoryName($repository); |
88
|
|
|
|
89
|
|
|
$this->branch = (string) $branch; |
90
|
|
|
$this->credentials = $credentials; |
91
|
|
|
$this->reference = (string) $reference; |
92
|
|
|
$this->repository = (string) $repository; |
93
|
|
|
|
94
|
|
|
list($this->vendor, $this->package) = explode('/', $repository); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
////////////////////////////// UTILITY METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
98
|
|
|
/** |
99
|
|
|
* @param $repository |
100
|
|
|
*/ |
101
|
|
|
private function isValidRepositoryName($repository) |
102
|
|
|
{ |
103
|
|
|
if (is_string($repository) === false |
104
|
|
|
|| preg_match('#^[^/]+/[^/]+$#', $repository) !== 1 |
105
|
|
|
) { |
106
|
|
|
$message = sprintf( |
107
|
|
|
self::ERROR_INVALID_REPOSITORY_NAME, |
108
|
|
|
var_export($repository, true) |
109
|
|
|
); |
110
|
|
|
throw new \InvalidArgumentException($message); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/*EOF*/ |
116
|
|
|
|