blob: 373348e8e080b7bb199c8b1f5c9c8e2316cdccef (
plain)
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
|
<?php
namespace Alias;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Package\AliasPackage;
use Composer\Package\CompleteAliasPackage;
use Composer\Package\RootAliasPackage;
use Composer\Plugin\PluginInterface;
class Plugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io)
{
$aliased = null;
foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
if (!$package instanceof AliasPackage) {
continue;
}
$aliased = $package->getAliasOf();
$io->write('alias: ' . self::describe($package));
$io->write('alias description: ' . $package->getDescription());
$io->write('alias self-version: ' . ($package->hasSelfVersionRequires() ? 'yes' : 'no'));
$io->write('alias root-flag: ' . ($package->isRootPackageAlias() ? 'yes' : 'no'));
$package->setRootPackageAlias(true);
$io->write('alias root-flag: ' . ($package->isRootPackageAlias() ? 'yes' : 'no'));
}
$root = $composer->getPackage();
if (!$root instanceof RootAliasPackage) {
throw new \RuntimeException('not a RootAliasPackage: ' . get_class($root));
}
$io->write('root: ' . self::describe($root));
$io->write('root aliasOf identity: ' . ($root->getAliasOf() === $root->getAliasOf() ? 'same' : 'distinct'));
$io->write('root minimum stability: ' . $root->getMinimumStability());
$root->setMinimumStability('dev');
$root->setExtra(['seen-by' => 'alias-v1']);
$built = new CompleteAliasPackage($aliased, '9.9.9.9', '9.9.9');
$io->write('built: ' . self::describe($built));
}
public function deactivate(Composer $composer, IOInterface $io)
{
}
public function uninstall(Composer $composer, IOInterface $io)
{
}
private static function describe(AliasPackage $package): string
{
return sprintf(
'%s %s %s of %s %s',
get_class($package),
$package->getName(),
$package->getPrettyVersion(),
get_class($package->getAliasOf()),
$package->getAliasOf()->getPrettyVersion()
);
}
}
|