1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Build tool mixed with code generator for easier automation and 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 Exception; |
15
|
|
|
use hidev\helpers\Helper; |
16
|
|
|
use yii\base\InvalidParamException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Init controller. |
20
|
|
|
* Builds .hidev/config.yml by template and params. |
21
|
|
|
*/ |
22
|
|
|
class InitController extends TemplateController |
23
|
|
|
{ |
24
|
|
|
protected $_file = '.hidev/config.yml'; |
25
|
|
|
|
26
|
|
|
public $vendor; |
27
|
|
|
public $package; |
28
|
|
|
|
29
|
3 |
|
public function prepareData($name) |
30
|
|
|
{ |
31
|
|
|
list($vendor, $package) = explode('/', $name, 2); |
32
|
3 |
|
if ($vendor) { |
33
|
3 |
|
$this->vendor = $vendor; |
34
|
3 |
|
$vendorPlugin = "$vendor/hidev-$vendor"; |
35
|
|
|
try { |
36
|
|
|
$exists = @file_get_contents("https://packagist.org/packages/$vendorPlugin.json"); |
37
|
|
|
} catch (Exception $e) { |
38
|
|
|
$exists = false; |
39
|
3 |
|
} |
40
|
3 |
|
if ($exists) { |
41
|
|
|
$this->setItem('vendorRequire', str_pad($vendorPlugin . ':', 23) . ' "*"'); |
|
|
|
|
42
|
|
|
$this->setItem('novendor', true); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
} |
45
|
3 |
|
if ($package) { |
46
|
3 |
|
$this->package = $package; |
47
|
|
|
} |
48
|
3 |
|
if (!$this->package || !$this->vendor) { |
49
|
|
|
throw new InvalidParamException('Wrong vendor/package given: ' . $name); |
50
|
|
|
} |
51
|
3 |
|
} |
52
|
|
|
|
53
|
3 |
|
public function actionPerform($name = null, $template = '.hidev/config') |
54
|
|
|
{ |
55
|
3 |
|
$this->_template = $template; |
56
|
|
|
$this->prepareData($name); |
57
|
|
|
if (!file_exists($this->dirname)) { |
|
|
|
|
58
|
|
|
mkdir($this->dirname); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return parent::actionPerform(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function options($actionId) |
65
|
|
|
{ |
66
|
|
|
return array_merge(parent::options($actionId), explode(',', 'namespace,headline,title,type,license,keywords,description,year,nick,author,email,novendor,norequire')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getType() |
70
|
|
|
{ |
71
|
|
|
return $this->getItem('type') ?: 'project'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getTitle() |
75
|
|
|
{ |
76
|
|
|
return $this->getItem('title') ?: Helper::titleize($this->package); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getKeywords() |
80
|
|
|
{ |
81
|
|
|
return $this->getItem('keywords') ?: implode(', ', explode('-', $this->package)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/// TODO think of better getting nick |
85
|
|
|
public function getNick() |
86
|
|
|
{ |
87
|
|
|
return $this->getItem('nick') ?: preg_replace('/[^a-zA-Z_0-9]+/', '', `id -un`); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getAuthor() |
91
|
|
|
{ |
92
|
|
|
return $this->getItem('author') ?: $this->takeVcs()->getUserName(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function getEmail() |
96
|
|
|
{ |
97
|
|
|
return $this->getItem('email') ?: $this->takeVcs()->getUserEmail(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
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: