|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Composer; |
|
4
|
|
|
|
|
5
|
|
|
use App\Document\Backend; |
|
6
|
|
|
use Composer\Config; |
|
7
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
|
8
|
|
|
|
|
9
|
|
|
class Factory |
|
10
|
|
|
{ |
|
11
|
|
|
protected $composerDir; |
|
12
|
|
|
protected $dm; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(DocumentManager $dm, string $composerDir) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->composerDir = $composerDir; |
|
17
|
|
|
$this->dm = $dm; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function createConfig(): Config |
|
21
|
|
|
{ |
|
22
|
|
|
$config = new Config(false, $this->composerDir); |
|
23
|
|
|
|
|
24
|
|
|
$config->merge(['config' => [ |
|
25
|
|
|
'home' => $this->composerDir, |
|
26
|
|
|
'cache-dir' => $this->composerDir.'/cache', |
|
27
|
|
|
'data-dir' => $this->composerDir.'/data', |
|
28
|
|
|
]]); |
|
29
|
|
|
|
|
30
|
|
|
$backend = $this->dm->getRepository('App:Backend')->findAll(); |
|
31
|
|
|
|
|
32
|
|
|
$gitlabDomains = ['gitlab.com']; |
|
33
|
|
|
$gitlabTokens = []; |
|
34
|
|
|
$githubDomains = ['github.com']; |
|
35
|
|
|
$githubOauth = []; |
|
36
|
|
|
|
|
37
|
|
|
/** @var Backend $conf */ |
|
38
|
|
|
foreach ($backend as $conf) { |
|
39
|
|
|
if (Backend::TYPE_GITLAB === $conf->getType()) { |
|
40
|
|
|
$gitlabDomains[] = $conf->getDomain(); |
|
41
|
|
|
$gitlabTokens[$conf->getDomain()] = $conf->getToken(); |
|
42
|
|
|
} |
|
43
|
|
|
if (Backend::TYPE_GITHUB === $conf->getType()) { |
|
44
|
|
|
$githubDomains[] = $conf->getDomain(); |
|
45
|
|
|
$githubOauth[$conf->getDomain()] = $conf->getToken(); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$config->merge(['config' => [ |
|
50
|
|
|
'gitlab-domains' => array_unique($gitlabDomains), |
|
51
|
|
|
'gitlab-token' => $gitlabTokens, |
|
52
|
|
|
'github-domains' => array_unique($githubDomains), |
|
53
|
|
|
'github-oauth' => $githubOauth, |
|
54
|
|
|
]]); |
|
55
|
|
|
|
|
56
|
|
|
return $config; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|