1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the composer-changelogs project. |
5
|
|
|
* |
6
|
|
|
* (c) Loïck Piera <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Pyrech\ComposerChangelogs\OperationHandler; |
13
|
|
|
|
14
|
|
|
use Composer\DependencyResolver\Operation\OperationInterface; |
15
|
|
|
use Composer\DependencyResolver\Operation\UninstallOperation; |
16
|
|
|
use Composer\Package\Version\VersionParser; |
17
|
|
|
use Pyrech\ComposerChangelogs\UrlGenerator\UrlGenerator; |
18
|
|
|
use Pyrech\ComposerChangelogs\Version; |
19
|
|
|
|
20
|
|
|
class UninstallHandler implements OperationHandler |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
4 |
|
public function supports(OperationInterface $operation) |
26
|
|
|
{ |
27
|
4 |
|
return $operation instanceof UninstallOperation; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
4 |
|
public function extractSourceUrl(OperationInterface $operation) |
34
|
|
|
{ |
35
|
4 |
|
if (!($operation instanceof UninstallOperation)) { |
36
|
2 |
|
throw new \LogicException('Operation should be an instance of UninstallOperation'); |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
return $operation->getPackage()->getSourceUrl(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
10 |
|
public function getOutput(OperationInterface $operation, UrlGenerator $urlGenerator = null) |
46
|
|
|
{ |
47
|
10 |
|
if (!($operation instanceof UninstallOperation)) { |
48
|
2 |
|
throw new \LogicException('Operation should be an instance of UninstallOperation'); |
49
|
|
|
} |
50
|
|
|
|
51
|
8 |
|
$output = []; |
52
|
|
|
|
53
|
8 |
|
$package = $operation->getPackage(); |
54
|
8 |
|
$version = new Version( |
55
|
8 |
|
$package->getVersion(), |
56
|
8 |
|
$package->getPrettyVersion(), |
57
|
8 |
|
method_exists($package, 'getFullPrettyVersion') // This method was added after composer v1.0.0-alpha10 |
58
|
8 |
|
? $package->getFullPrettyVersion() |
59
|
8 |
|
: VersionParser::formatVersion($package) |
60
|
8 |
|
); |
61
|
|
|
|
62
|
8 |
|
$output[] = sprintf( |
63
|
8 |
|
' - <fg=green>%s</fg=green> removed (installed version was <fg=yellow>%s</fg=yellow>)', |
64
|
8 |
|
$package->getName(), |
65
|
8 |
|
$version->getPretty() |
66
|
8 |
|
); |
67
|
|
|
|
68
|
8 |
|
return $output; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|