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