|
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 function getBin() |
|
24
|
|
|
{ |
|
25
|
|
|
if ($this->_bin === null) { |
|
26
|
|
|
$this->_bin = $this->detectBin(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
return $this->_bin; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function detectBin() |
|
33
|
|
|
{ |
|
34
|
|
|
if ($this->takePackage()->fullName === 'hiqdev/hidev') { |
|
35
|
|
|
return './bin/hidev'; |
|
36
|
|
|
} |
|
37
|
|
|
if ($this->takePackage()->hasRequireAny('hiqdev/hidev')) { |
|
38
|
|
|
return './vendor/bin/hidev'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return './hidev.phar'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getBeforeInstall() |
|
45
|
|
|
{ |
|
46
|
|
|
$commands = array_values(array_unique($this->get('before_install'))); |
|
47
|
|
|
if ($this->bin === './hidev.phar') { |
|
|
|
|
|
|
48
|
|
|
$commands[] = 'wget http://hiqdev.com/hidev/hidev.phar -O hidev.phar && chmod a+x hidev.phar'; |
|
49
|
|
|
} |
|
50
|
|
|
if ($this->bin === './bin/hidev') { |
|
|
|
|
|
|
51
|
|
|
$commands[] = 'travis_retry composer install --no-interaction'; |
|
52
|
|
|
} |
|
53
|
|
|
$commands[] = $this->getBin() . ' --version'; |
|
54
|
|
|
$commands[] = $this->getBin() . ' travis/before_install'; |
|
55
|
|
|
|
|
56
|
|
|
return $commands; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Reorders config elements. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function actionSave() |
|
63
|
|
|
{ |
|
64
|
|
|
$add_items = [ |
|
65
|
|
|
'sudo' => false, |
|
66
|
|
|
'before_install' => $this->getBeforeInstall(), |
|
67
|
|
|
]; |
|
68
|
|
|
foreach (['install', 'before_script', 'script', 'after_success', 'after_failure', 'after_script'] as $event) { |
|
69
|
|
|
if ($this->getTravis()->{$event}) { |
|
70
|
|
|
$add_items[$event] = [$this->getBin() . ' travis/' . $event]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
$this->setItems($add_items); |
|
74
|
|
|
$items = $this->_items; |
|
75
|
|
|
$lang = $items['language']; |
|
76
|
|
|
$lops = $items[$lang]; |
|
77
|
|
|
unset($items['language'], $items[$lang]); |
|
78
|
|
|
$this->_items = [ |
|
79
|
|
|
'language' => $lang, |
|
80
|
|
|
$lang => $lops, |
|
81
|
|
|
] + $items; |
|
82
|
|
|
return parent::actionSave(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getTravis() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->takeGoal('travis'); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
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@propertyannotation 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.