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