1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Composer plugin for HiDev |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hidev-composer |
7
|
|
|
* @package hidev-composer |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hidev\composer\controllers; |
13
|
|
|
|
14
|
|
|
use Yii; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Goal for Composer. |
18
|
|
|
*/ |
19
|
|
|
class ComposerController extends \hidev\controllers\CommonController |
20
|
|
|
{ |
21
|
|
|
protected $_before = ['composer.json']; |
22
|
|
|
|
23
|
|
|
public function actionInstall() |
24
|
|
|
{ |
25
|
|
|
return $this->runActions(['before', 'do-install', 'after']); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function actionUpdate() |
29
|
|
|
{ |
30
|
|
|
return $this->runActions(['before', 'do-update', 'after']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function actionSelfUpdate($version = null) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return $this->run('self-update', ''); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function actionDoInstall() |
39
|
|
|
{ |
40
|
|
|
$dir = Yii::getAlias('@prjdir/vendor'); |
41
|
|
|
|
42
|
|
|
return is_dir($dir) ? 0 : $this->run('install'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function actionDoUpdate() |
46
|
|
|
{ |
47
|
|
|
return $this->run('update'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function run($command, $dir = null) |
51
|
|
|
{ |
52
|
|
|
if ($dir === null) { |
53
|
|
|
$dir = Yii::getAlias('@prjdir'); |
54
|
|
|
} |
55
|
|
|
$args = [$command, '--ansi']; |
56
|
|
|
if ($dir) { |
57
|
|
|
$args[] = '-d'; |
58
|
|
|
$args[] = $dir; |
59
|
|
|
} |
60
|
|
|
return $this->passthru('composer', $args); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getNamespace() |
64
|
|
|
{ |
65
|
|
|
return @trim(key($this->getConfiguration()->getFile()->get('autoload')['psr-4']), '\\'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getFullName() |
69
|
|
|
{ |
70
|
|
|
return $this->getConfiguration()->getFullName(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getConfiguration() |
74
|
|
|
{ |
75
|
|
|
$conf = $this->takeGoal('composer.json'); |
76
|
|
|
$conf->runAction('load'); |
77
|
|
|
return $conf; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.