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