|
1
|
|
|
<?php namespace Arcanedev\Composer\Entities\PackageTraits; |
|
2
|
|
|
|
|
3
|
|
|
use Composer\Package\BasePackage; |
|
4
|
|
|
use Composer\Package\RootPackageInterface; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Trait LinksTrait |
|
8
|
|
|
* |
|
9
|
|
|
* @package Arcanedev\Composer\Entities\PackageTraits |
|
10
|
|
|
* @author ARCANEDEV <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
trait LinksTrait |
|
13
|
|
|
{ |
|
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
15
|
|
|
| Properties |
|
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
17
|
|
|
*/ |
|
18
|
|
|
/** @var \Arcanedev\Composer\Utilities\Logger $logger */ |
|
19
|
|
|
protected $logger; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \Composer\Package\CompletePackage $package */ |
|
22
|
|
|
protected $package; |
|
23
|
|
|
|
|
24
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
25
|
|
|
| Main Functions |
|
26
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
27
|
|
|
*/ |
|
28
|
|
|
/** |
|
29
|
|
|
* Merge package links of the given type into a RootPackageInterface |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $type 'conflict', 'replace' or 'provide' |
|
32
|
|
|
* @param \Composer\Package\RootPackageInterface $root |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function mergePackageLinks($type, RootPackageInterface $root) |
|
35
|
|
|
{ |
|
36
|
|
|
$linkType = BasePackage::$supportedLinkTypes[$type]; |
|
37
|
|
|
$getter = 'get' . ucfirst($linkType['method']); |
|
38
|
|
|
$setter = 'set' . ucfirst($linkType['method']); |
|
39
|
|
|
|
|
40
|
|
|
$links = $this->package->{$getter}(); |
|
41
|
|
|
|
|
42
|
|
|
if (empty($links)) return; |
|
43
|
|
|
|
|
44
|
|
|
$unwrapped = self::unwrapIfNeeded($root, $setter); |
|
45
|
|
|
|
|
46
|
|
|
// @codeCoverageIgnoreStart |
|
47
|
|
|
if ($root !== $unwrapped) { |
|
48
|
|
|
$this->logger->warning( |
|
49
|
|
|
'This Composer version does not support ' . |
|
50
|
|
|
"'{$type}' merging for aliased packages." |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
// @codeCoverageIgnoreEnd |
|
54
|
|
|
|
|
55
|
|
|
$unwrapped->{$setter}(array_merge( |
|
56
|
|
|
$root->{$getter}(), |
|
57
|
|
|
$this->replaceSelfVersionDependencies($type, $links, $root) |
|
58
|
|
|
)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Update Links with a 'self.version' constraint with the root package's version. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $type |
|
65
|
|
|
* @param array $links |
|
66
|
|
|
* @param \Composer\Package\RootPackageInterface $root |
|
67
|
|
|
* |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
abstract protected function replaceSelfVersionDependencies( |
|
71
|
|
|
$type, array $links, RootPackageInterface $root |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|