|
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) 2014-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
|
|
|
use \hiqdev\yii2\collection\ObjectTrait; |
|
24
|
|
|
|
|
25
|
|
|
protected $_file = '.hidev/config.yml'; |
|
26
|
|
|
|
|
27
|
|
|
public $vendor; |
|
28
|
|
|
public $package; |
|
29
|
|
|
|
|
30
|
|
|
public function actionPerform($name = null, $template = '.hidev/config') |
|
31
|
|
|
{ |
|
32
|
|
|
list($vendor, $package) = explode('/', $name, 2); |
|
33
|
|
|
if ($vendor) { |
|
34
|
|
|
$this->vendor = $vendor; |
|
35
|
|
|
} |
|
36
|
|
|
if ($package) { |
|
37
|
|
|
$this->package = $package; |
|
38
|
|
|
} |
|
39
|
|
|
if (!$this->package || !$this->vendor) { |
|
40
|
|
|
throw new InvalidParamException('Wrong vendor/package given: ' . $name); |
|
41
|
|
|
} |
|
42
|
|
|
$this->template = $template; |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
if (!file_exists($this->dirname)) { |
|
|
|
|
|
|
45
|
|
|
mkdir($this->dirname); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return parent::actionPerform(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function options($actionId) |
|
52
|
|
|
{ |
|
53
|
|
|
return array_merge(parent::options($actionId), explode(',', 'namespace,headline,title,type,license,keywords,description,year,nick,author,email,novendor,norequire')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getType() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->getItem('type') ?: 'project'; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getTitle() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->getItem('title') ?: Helper::titleize($this->package); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getKeywords() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->getItem('keywords') ?: implode(', ', explode('-', $this->package)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/// TODO think of better getting nick |
|
72
|
|
|
public function getNick() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->getItem('nick') ?: preg_replace('/[^a-zA-Z_0-9]+/', '', `id -un`); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getAuthor() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getItem('author') ?: $this->getVcs()->getUserName(); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getEmail() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->getItem('email') ?: $this->getVcs()->getUserEmail(); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.