1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the slince/composer-alias package. |
4
|
|
|
* |
5
|
|
|
* (c) Slince <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Slince\ComposerAlias; |
12
|
|
|
|
13
|
|
|
use Composer\Composer; |
14
|
|
|
use Composer\IO\IOInterface; |
15
|
|
|
use Composer\Json\JsonFile; |
16
|
|
|
use Composer\Plugin\Capability\CommandProvider; |
17
|
|
|
use Composer\Plugin\Capable; |
18
|
|
|
use Composer\Plugin\PluginInterface; |
19
|
|
|
use Slince\ComposerAlias\Command\ProxyCommand; |
20
|
|
|
|
21
|
|
|
class ComposerAlias implements PluginInterface, Capable, CommandProvider |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Composer |
25
|
|
|
*/ |
26
|
|
|
protected $composer; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var IOInterface |
30
|
|
|
*/ |
31
|
|
|
protected $io; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var AliasCollection |
35
|
|
|
*/ |
36
|
|
|
protected static $aliases; |
37
|
|
|
|
38
|
|
|
protected static $activated = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function activate(Composer $composer, IOInterface $io) |
44
|
|
|
{ |
45
|
|
|
$this->composer = $composer; |
46
|
|
|
$this->io = $io; |
47
|
|
|
$configFile = $this->composer->getConfig()->get('home').'/config.json'; |
48
|
|
|
static::$aliases = new AliasCollection(new JsonFile($configFile, null, $this->io)); |
49
|
|
|
static::$activated = true; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getCapabilities() |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
CommandProvider::class => __CLASS__, |
59
|
|
|
]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
|
|
public function getCommands() |
66
|
|
|
{ |
67
|
|
|
$commands = [ |
68
|
|
|
new Command\AliasCommand($this), |
69
|
|
|
]; |
70
|
|
|
foreach (array_keys($this->getAliases()->all()) as $alias) { |
71
|
|
|
$commands[] = new ProxyCommand($alias, $this); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $commands; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return AliasCollection |
79
|
|
|
*/ |
80
|
|
|
public function getAliases() |
81
|
|
|
{ |
82
|
|
|
return static::$aliases; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|