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