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\InstallOperation; |
15
|
|
|
use Composer\DependencyResolver\Operation\OperationInterface; |
16
|
|
|
use Composer\Package\Version\VersionParser; |
17
|
|
|
use Pyrech\ComposerChangelogs\UrlGenerator\UrlGenerator; |
18
|
|
|
use Pyrech\ComposerChangelogs\Version; |
19
|
|
|
|
20
|
|
|
class InstallHandler implements OperationHandler |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
14 |
|
public function supports(OperationInterface $operation) |
26
|
|
|
{ |
27
|
14 |
|
return $operation instanceof InstallOperation; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
10 |
|
public function extractSourceUrl(OperationInterface $operation) |
34
|
|
|
{ |
35
|
10 |
|
if (!($operation instanceof InstallOperation)) { |
36
|
2 |
|
throw new \LogicException('Operation should be an instance of InstallOperation'); |
37
|
|
|
} |
38
|
|
|
|
39
|
8 |
|
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 InstallOperation)) { |
48
|
2 |
|
throw new \LogicException('Operation should be an instance of InstallOperation'); |
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> installed in version <fg=yellow>%s</fg=yellow>', |
64
|
8 |
|
$package->getName(), |
65
|
8 |
|
$version->getPretty() |
66
|
8 |
|
); |
67
|
|
|
|
68
|
8 |
|
if ($urlGenerator) { |
69
|
6 |
|
$releaseUrl = $urlGenerator->generateReleaseUrl( |
70
|
6 |
|
$this->extractSourceUrl($operation), |
71
|
|
|
$version |
72
|
6 |
|
); |
73
|
|
|
|
74
|
6 |
|
if (!empty($releaseUrl)) { |
75
|
4 |
|
$output[] = sprintf( |
76
|
4 |
|
' Release notes: %s', |
77
|
|
|
$releaseUrl |
78
|
4 |
|
); |
79
|
4 |
|
} |
80
|
6 |
|
} |
81
|
|
|
|
82
|
8 |
|
return $output; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|