1
|
|
|
<?php namespace Arcanedev\Composer\Entities\PackageTraits; |
2
|
|
|
|
3
|
|
|
use Composer\Package\BasePackage; |
4
|
|
|
use Composer\Package\Link; |
5
|
|
|
use Composer\Package\RootAliasPackage; |
6
|
|
|
use Composer\Package\RootPackageInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trait BaseTrait |
10
|
|
|
* |
11
|
|
|
* @package Arcanedev\Composer\Entities\PackageTraits |
12
|
|
|
* @author ARCANEDEV <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
trait BaseTrait |
15
|
|
|
{ |
16
|
|
|
/* ------------------------------------------------------------------------------------------------ |
17
|
|
|
| Other Functions |
18
|
|
|
| ------------------------------------------------------------------------------------------------ |
19
|
|
|
*/ |
20
|
|
|
/** |
21
|
|
|
* Update Links with a 'self.version' constraint with the root package's version. |
22
|
|
|
* |
23
|
|
|
* @param string $type |
24
|
|
|
* @param array $links |
25
|
|
|
* @param \Composer\Package\RootPackageInterface $root |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
protected function replaceSelfVersionDependencies( |
30
|
|
|
$type, array $links, RootPackageInterface $root |
31
|
|
|
) { |
32
|
|
|
$linkType = BasePackage::$supportedLinkTypes[$type]; |
33
|
|
|
$version = $root->getVersion(); |
34
|
|
|
$prettyVersion = $root->getPrettyVersion(); |
35
|
|
|
$vp = $this->versionParser; |
|
|
|
|
36
|
|
|
$packages = $root->{'get' . ucfirst($linkType['method'])}(); |
37
|
|
|
|
38
|
|
|
return array_map(function (Link $link) use ($linkType, $version, $prettyVersion, $vp, $packages) { |
39
|
|
|
if ($link->getPrettyConstraint() !== 'self.version') { |
40
|
|
|
return $link; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if (isset($packages[$link->getSource()])) { |
44
|
|
|
/** @var \Composer\Package\Link $package */ |
45
|
|
|
$package = $packages[$link->getSource()]; |
46
|
|
|
$version = $package->getConstraint()->getPrettyString(); |
|
|
|
|
47
|
|
|
$prettyVersion = $package->getPrettyConstraint(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return new Link( |
51
|
|
|
$link->getSource(), |
52
|
|
|
$link->getTarget(), |
53
|
|
|
$vp->parseConstraints($version), |
54
|
|
|
$linkType['description'], |
55
|
|
|
$prettyVersion |
56
|
|
|
); |
57
|
|
|
}, $links); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get a full featured Package from a RootPackageInterface. |
62
|
|
|
* |
63
|
|
|
* @param \Composer\Package\RootPackageInterface|\Composer\Package\RootPackage $root |
64
|
|
|
* @param string $method |
65
|
|
|
* |
66
|
|
|
* @return \Composer\Package\RootPackageInterface|\Composer\Package\RootPackage |
67
|
|
|
*/ |
68
|
|
|
private static function unwrapIfNeeded( |
|
|
|
|
69
|
|
|
RootPackageInterface $root, $method = 'setExtra' |
70
|
|
|
) { |
71
|
|
|
return ($root instanceof RootAliasPackage && ! method_exists($root, $method)) |
72
|
|
|
? $root->getAliasOf() |
73
|
|
|
: $root; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: