1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Travis CI plugin for HiDev |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hidev-travis |
7
|
|
|
* @package hidev-travis |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hidev\travis\controllers; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Goal for .travis.yml config file. |
16
|
|
|
*/ |
17
|
|
|
class TravisYamlController extends \hidev\controllers\FileController |
18
|
|
|
{ |
19
|
|
|
protected $_file = '.travis.yml'; |
20
|
|
|
|
21
|
|
|
protected $_bin; |
22
|
|
|
|
23
|
|
|
public $sudo = false; |
24
|
|
|
|
25
|
|
|
public function getBin() |
26
|
|
|
{ |
27
|
|
|
if ($this->_bin === null) { |
28
|
|
|
$this->_bin = $this->detectBin(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return $this->_bin; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function detectBin() |
35
|
|
|
{ |
36
|
|
|
if ($this->takePackage()->fullName === 'hiqdev/hidev') { |
37
|
|
|
return './bin/hidev'; |
38
|
|
|
} |
39
|
|
|
if ($this->takePackage()->hasRequireAny('hiqdev/hidev')) { |
40
|
|
|
return './vendor/bin/hidev'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return './hidev.phar'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getBeforeInstall() |
47
|
|
|
{ |
48
|
|
|
$commands = $this->get('before_install'); |
49
|
|
|
if ($this->getItem('language') != 'php') { |
50
|
|
|
$this->sudo = true; |
51
|
|
|
$commands[] = 'sudo add-apt-repository --yes ppa:ondrej/php'; |
52
|
|
|
$commands[] = 'sudo apt-get update'; |
53
|
|
|
$commands[] = 'sudo apt-get install php5.6-cli php5.6-mbstring'; |
54
|
|
|
$commands[] = 'env php -v'; |
55
|
|
|
} |
56
|
|
|
if ($this->bin === './hidev.phar') { |
|
|
|
|
57
|
|
|
$commands[] = 'wget http://hiqdev.com/hidev/hidev.phar -O hidev.phar && chmod a+x hidev.phar'; |
58
|
|
|
} else { |
59
|
|
|
$commands[] = 'composer install --no-interaction'; |
60
|
|
|
} |
61
|
|
|
$commands[] = $this->getBin() . ' --version'; |
62
|
|
|
$commands[] = $this->getBin() . ' travis/before_install'; |
63
|
|
|
|
64
|
|
|
return array_values(array_unique($commands)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Reorders config elements. |
69
|
|
|
*/ |
70
|
|
|
public function actionSave() |
71
|
|
|
{ |
72
|
|
|
$this->addActionItems(); |
73
|
|
|
$this->prependLanguageOptions(); |
74
|
|
|
|
75
|
|
|
return parent::actionSave(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function addActionItems() |
79
|
|
|
{ |
80
|
|
|
$add_items = [ |
81
|
|
|
'sudo' => false, |
82
|
|
|
'before_install' => $this->getBeforeInstall(), |
83
|
|
|
]; |
84
|
|
|
foreach (['install', 'before_script', 'script', 'after_success', 'after_failure', 'after_script'] as $event) { |
85
|
|
|
if ($this->takeGoal('travis')->{$event}) { |
86
|
|
|
$add_items[$event] = [$this->getBin() . ' travis/' . $event]; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
$this->setItems($add_items); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function prependLanguageOptions() |
93
|
|
|
{ |
94
|
|
|
$items = $this->_items; |
95
|
|
|
$language = $items['language'] ?: $this->takePackage()->getLanguage(); |
96
|
|
|
$lang_ops = $items[$language]; |
97
|
|
|
unset($items['language'], $items[$language]); |
98
|
|
|
$this->_items = [ |
99
|
|
|
'language' => $language, |
100
|
|
|
$language => $lang_ops, |
101
|
|
|
] + $items; |
102
|
|
|
$this->setItem('sudo', $this->sudo); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.