1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Task runner, code generator and build tool for easier continuos integration |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hidev |
7
|
|
|
* @package hidev |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hidev\controllers; |
13
|
|
|
|
14
|
|
|
use hidev\helpers\Helper; |
15
|
|
|
use yii\base\InvalidParamException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Init controller. |
19
|
|
|
* Builds .hidev/config.yml by template and params. |
20
|
|
|
*/ |
21
|
|
|
class InitController extends TemplateController |
22
|
|
|
{ |
23
|
|
|
protected $_file = '.hidev/config.yml'; |
24
|
|
|
|
25
|
|
|
public $vendor; |
26
|
|
|
public $package; |
27
|
|
|
|
28
|
|
|
public function prepareData($name) |
29
|
|
|
{ |
30
|
|
|
list($vendor, $package) = explode('/', $name, 2); |
31
|
|
|
if ($vendor) { |
32
|
|
|
$this->vendor = $vendor; |
33
|
|
|
if (GithubController::exists($name)) { |
34
|
|
|
$this->setItem('vendorRequire', str_pad($name . ':', 16)); |
|
|
|
|
35
|
|
|
$this->setItem('novendor', true); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
if ($package) { |
39
|
|
|
$this->package = $package; |
40
|
|
|
} |
41
|
|
|
if (!$this->package || !$this->vendor) { |
42
|
|
|
throw new InvalidParamException('Wrong vendor/package given: ' . $name); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function actionPerform($name = null, $template = '.hidev/config') |
47
|
|
|
{ |
48
|
|
|
$this->_template = $template; |
49
|
|
|
$this->prepareData($name); |
50
|
|
|
if (!file_exists($this->dirname)) { |
|
|
|
|
51
|
|
|
mkdir($this->dirname); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return parent::actionPerform(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function options($actionId) |
58
|
|
|
{ |
59
|
|
|
return array_merge(parent::options($actionId), explode(',', 'namespace,headline,title,type,license,keywords,description,year,nick,author,email,novendor,norequire')); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getType() |
63
|
|
|
{ |
64
|
|
|
return $this->getItem('type') ?: 'project'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getTitle() |
68
|
|
|
{ |
69
|
|
|
return $this->getItem('title') ?: Helper::titleize($this->package); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getKeywords() |
73
|
|
|
{ |
74
|
|
|
return $this->getItem('keywords') ?: implode(', ', explode('-', $this->package)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/// TODO think of better getting nick |
78
|
|
|
public function getNick() |
79
|
|
|
{ |
80
|
|
|
return $this->getItem('nick') ?: preg_replace('/[^a-zA-Z_0-9]+/', '', `id -un`); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getAuthor() |
84
|
|
|
{ |
85
|
|
|
return $this->getItem('author') ?: $this->takeVcs()->getUserName(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getEmail() |
89
|
|
|
{ |
90
|
|
|
return $this->getItem('email') ?: $this->takeVcs()->getUserEmail(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: