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
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Package part of the config. |
18
|
|
|
* |
19
|
|
|
* @property string name |
20
|
|
|
* @property string year |
21
|
|
|
* @property string source |
22
|
|
|
*/ |
23
|
|
|
class PackageController extends CommonController |
24
|
|
|
{ |
25
|
|
|
use \hiqdev\yii2\collection\ObjectTrait; |
26
|
|
|
|
27
|
|
|
public function getType() |
28
|
|
|
{ |
29
|
|
|
return $this->getItem('type') ?: 'project'; |
30
|
|
|
} |
31
|
|
|
|
32
|
2 |
|
public function getYears() |
33
|
|
|
{ |
34
|
|
|
$years = $this->getItem('years'); |
35
|
2 |
|
if (!empty($years)) { |
36
|
2 |
|
return $years; |
37
|
|
|
} |
38
|
|
|
$cur = (integer) date('Y'); |
39
|
|
|
$old = (integer) $this->year; |
40
|
|
|
|
41
|
|
|
return ($old && $old < $cur ? $this->year . '-' : '') . $cur; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getYear() |
45
|
|
|
{ |
46
|
|
|
return $this->getItem('year') ?: $this->takeVcs()->getYear(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getLicense() |
50
|
|
|
{ |
51
|
|
|
return $this->getItem('license') ?: $this->takeVendor()->license ?: 'No license'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getIssues() |
55
|
|
|
{ |
56
|
|
|
return $this->getItem('issues') ?: ($this->source . '/issues'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getWiki() |
60
|
|
|
{ |
61
|
|
|
return $this->getItem('wiki') ?: ($this->source . '/wiki'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getKeywords() |
65
|
|
|
{ |
66
|
|
|
return Helper::csplit($this->getItem('keywords')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getFullName() |
70
|
|
|
{ |
71
|
|
|
return $this->getItem('fullName') ?: ($this->takeVendor()->name . '/' . $this->name); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getSource() |
75
|
|
|
{ |
76
|
|
|
return $this->getItem('source') ?: ('https://github.com/' . $this->takeGoal('github')->full_name); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getVersion() |
80
|
|
|
{ |
81
|
|
|
return $this->takeGoal('version')->version; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getNamespace() |
85
|
|
|
{ |
86
|
|
|
return $this->getItem('namespace') ?: $this->getPackageManager()->namespace ?: self::defaultNamespace($this->takeVendor()->name, $this->name); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public static function defaultNamespace($vendor, $package) |
90
|
|
|
{ |
91
|
|
|
return preg_replace('/[^a-zA-Z0-9\\\\]+/', '', $vendor . strtr("-$package", '-', '\\')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getSrc() |
95
|
|
|
{ |
96
|
|
|
$src = $this->rawItem('src'); |
97
|
|
|
|
98
|
|
|
return isset($src) ? $src : 'src'; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getHomepage() |
102
|
|
|
{ |
103
|
|
|
return $this->getItem('homepage') ?: ($this->isDomain() ? 'http://' . $this->name . '/' : $this->getSource()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getForum() |
107
|
|
|
{ |
108
|
|
|
return $this->getItem('forum') ?: $this->takeVendor()->forum; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getLabel() |
112
|
|
|
{ |
113
|
|
|
return $this->getItem('label') ?: $this->getHeadline() ?: Helper::id2camel($this->name); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function isDomain() |
117
|
|
|
{ |
118
|
|
|
return preg_match('/^[a-z0-9-]+(\.[a-z0-9]+)+$/', $this->name); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getTitle() |
122
|
|
|
{ |
123
|
|
|
return $this->getItem('title') ?: ($this->isDomain() ? $this->name : Helper::titleize($this->name)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function getHeadline() |
127
|
|
|
{ |
128
|
|
|
return $this->getItem('headline'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function getDescription() |
132
|
|
|
{ |
133
|
|
|
return $this->getItem('description'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getRepositoryUrl($file) |
137
|
|
|
{ |
138
|
|
|
return 'https://github.com/' . $this->getFullName() . '/blob/master/' . $file; |
139
|
|
|
} |
140
|
|
|
public function getAuthors() |
141
|
|
|
{ |
142
|
|
|
return $this->getItem('authors') ?: $this->takeVendor()->authors; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Composer for the moment. |
147
|
|
|
* To be changed to get actual Package Manager. |
148
|
|
|
*/ |
149
|
|
|
public function getPackageManager() |
150
|
|
|
{ |
151
|
|
|
return $this->takeGoal('composer'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function hasRequireAny($package) |
155
|
|
|
{ |
156
|
|
|
return $this->hasRequire($package) || $this->hasRequireDev($package); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function hasRequire($package) |
160
|
|
|
{ |
161
|
|
|
$pman = $this->getPackageManager(); |
162
|
|
|
|
163
|
|
|
return $pman && array_key_exists($package, $pman->getConfiguration()->getRequire()); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function hasRequireDev($package) |
167
|
|
|
{ |
168
|
|
|
$pman = $this->getPackageManager(); |
169
|
|
|
|
170
|
|
|
return $pman && array_key_exists($package, $pman->getConfiguration()->getRequireDev()); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|