1
|
|
|
<?php namespace Arcanedev\Composer\Entities\PackageTraits; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Composer\Entities\PluginState; |
4
|
|
|
use Composer\Package\RootPackageInterface; |
5
|
|
|
use Composer\Repository\RepositoryManager; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait RepositoriesTrait |
9
|
|
|
* |
10
|
|
|
* @package Arcanedev\Composer\Entities\PackageTraits |
11
|
|
|
* @author ARCANEDEV <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
trait RepositoriesTrait |
14
|
|
|
{ |
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
16
|
|
|
| Traits |
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
18
|
|
|
*/ |
19
|
|
|
use PackageTrait; |
20
|
|
|
|
21
|
|
|
/* ------------------------------------------------------------------------------------------------ |
22
|
|
|
| Main Functions |
23
|
|
|
| ------------------------------------------------------------------------------------------------ |
24
|
|
|
*/ |
25
|
|
|
/** |
26
|
|
|
* Add a collection of repositories described by the given configuration |
27
|
|
|
* to the given package and the global repository manager. |
28
|
|
|
* |
29
|
|
|
* @param \Composer\Package\RootPackageInterface $root |
30
|
|
|
* @param \Arcanedev\Composer\Entities\PluginState $state |
31
|
|
|
*/ |
32
|
|
|
private function addRepositories(RootPackageInterface $root, PluginState $state) |
33
|
|
|
{ |
34
|
|
|
$json = $this->getJson(); |
35
|
|
|
|
36
|
|
|
if (isset($json['repositories'])) { |
37
|
|
|
$prepend = $state->shouldPrependRepositories(); |
38
|
|
|
$repoManager = $this->getComposer()->getRepositoryManager(); |
39
|
|
|
$repositories = []; |
40
|
|
|
|
41
|
|
|
foreach ($json['repositories'] as $repoJson) { |
42
|
|
|
$this->addRepository($repoManager, $repositories, $repoJson, $prepend); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** @var \Composer\Package\RootPackageInterface $unwrapped */ |
46
|
|
|
$unwrapped = self::unwrapIfNeeded($root, 'setRepositories'); |
47
|
|
|
$mergedRepos = $prepend |
48
|
|
|
? array_merge($repositories, $root->getRepositories()) |
49
|
|
|
: array_merge($root->getRepositories(), $repositories); |
50
|
|
|
|
51
|
|
|
$unwrapped->setRepositories($mergedRepos); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/* ------------------------------------------------------------------------------------------------ |
56
|
|
|
| Other Functions |
57
|
|
|
| ------------------------------------------------------------------------------------------------ |
58
|
|
|
*/ |
59
|
|
|
/** |
60
|
|
|
* Add a repository to collection of repositories. |
61
|
|
|
* |
62
|
|
|
* @param \Composer\Repository\RepositoryManager $repoManager |
63
|
|
|
* @param array $repositories |
64
|
|
|
* @param array $repoJson |
65
|
|
|
* @param bool $prepend |
66
|
|
|
*/ |
67
|
|
|
private function addRepository( |
68
|
|
|
RepositoryManager $repoManager, array &$repositories, $repoJson, $prepend |
69
|
|
|
) { |
70
|
|
|
if (isset($repoJson['type'])) { |
71
|
|
|
$this->getLogger()->info( |
72
|
|
|
$prepend ? "Prepending {$repoJson['type']} repository" : "Adding {$repoJson['type']} repository" |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$repository = $repoManager->createRepository($repoJson['type'], $repoJson); |
76
|
|
|
|
77
|
|
|
$prepend |
78
|
|
|
? $repoManager->prependRepository($repository) |
79
|
|
|
: $repoManager->addRepository($repository); |
80
|
|
|
|
81
|
|
|
$repositories[] = $repository; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|