-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiePackageInstaller.php
More file actions
134 lines (116 loc) · 4.65 KB
/
Copy pathPiePackageInstaller.php
File metadata and controls
134 lines (116 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
declare(strict_types=1);
namespace Php\Pie\ComposerIntegration;
use Composer\Installer\LibraryInstaller;
use Composer\IO\IOInterface;
use Composer\Package\CompletePackageInterface;
use Composer\Package\PackageInterface;
use Composer\PartialComposer;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Util\Filesystem;
use Php\Pie\DependencyResolver\RequestedPackageAndVersion;
use Php\Pie\ExtensionType;
use function array_map;
use function implode;
use function sprintf;
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
class PiePackageInstaller extends LibraryInstaller
{
public function __construct(
IOInterface $io,
PartialComposer $composer,
ExtensionType $type,
Filesystem $filesystem,
private readonly InstallAndBuildProcess $installAndBuildProcess,
private readonly UninstallProcess $uninstallProcess,
private readonly PieComposerRequest $composerRequest,
) {
parent::__construct($io, $composer, $type->value, $filesystem);
}
/** @inheritDoc */
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$composerPackage = $package;
return parent::install($repo, $composerPackage)
?->then($this->onlyForRequestedPiePackage(
$composerPackage,
'install',
function (CompletePackageInterface $composerPackage): void {
($this->installAndBuildProcess)(
$this->composer,
$this->composerRequest,
$composerPackage,
$this->getInstallPath($composerPackage),
);
},
));
}
/** @inheritDoc */
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
$composerPackage = $target;
return parent::update($repo, $initial, $target)
?->then($this->onlyForRequestedPiePackage(
$composerPackage,
'update',
function (CompletePackageInterface $composerPackage): void {
($this->installAndBuildProcess)(
$this->composer,
$this->composerRequest,
$composerPackage,
$this->getInstallPath($composerPackage),
);
},
));
}
/** @inheritDoc */
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$composerPackage = $package;
return parent::uninstall($repo, $composerPackage)
?->then($this->onlyForRequestedPiePackage(
$composerPackage,
'uninstall',
function (CompletePackageInterface $composerPackage): void {
($this->uninstallProcess)(
$this->composerRequest,
$composerPackage,
);
},
));
}
/**
* Wraps the given callback so it only runs when Composer's operation is for a PIE package we actually
* requested, and that package has full metadata available.
*
* @return callable(): null
*/
private function onlyForRequestedPiePackage(PackageInterface $composerPackage, string $verb, callable $onVerified): callable
{
return function () use ($composerPackage, $verb, $onVerified) {
$io = $this->composerRequest->pieOutput;
if (! $this->composerRequest->isFor($composerPackage->getName())) {
$io->write(
sprintf(
'<comment>Skipping %s %s request from Composer as it was not the expected PIE package(s) %s</comment>',
$composerPackage->getName(),
$verb,
implode(', ', array_map(static fn (RequestedPackageAndVersion $req) => $req->package, $this->composerRequest->requestedPackages)),
),
verbosity: IOInterface::VERY_VERBOSE,
);
return null;
}
if (! $composerPackage instanceof CompletePackageInterface) {
$io->writeError(sprintf(
'<error>Not using PIE to %s %s as it was not a Complete Package</error>',
$verb,
$composerPackage->getName(),
));
return null;
}
$onVerified($composerPackage);
return null;
};
}
}