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