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
|
|
|
class PackageController extends CommonController |
20
|
|
|
{ |
21
|
|
|
use \hiqdev\yii2\collection\ObjectTrait; |
22
|
|
|
|
23
|
|
|
public function getYears() |
24
|
|
|
{ |
25
|
|
|
$cur = (integer) date('Y'); |
26
|
|
|
$old = (integer) $this->year; |
|
|
|
|
27
|
|
|
|
28
|
|
|
return ($old && $old < $cur ? $this->year . '-' : '') . $cur; |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getYear() |
32
|
|
|
{ |
33
|
|
|
return $this->getItem('year') ?: $this->takeVcs()->getYear(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getLicense() |
37
|
|
|
{ |
38
|
|
|
return $this->getItem('license') ?: $this->takeVendor()->license ?: 'No license'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getIssues() |
42
|
|
|
{ |
43
|
|
|
return $this->getItem('issues') ?: ($this->source . '/issues'); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getWiki() |
47
|
|
|
{ |
48
|
|
|
return $this->getItem('wiki') ?: ($this->source . '/wiki'); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getKeywords() |
52
|
|
|
{ |
53
|
|
|
return Helper::csplit($this->getItem('keywords')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getFullName() |
57
|
|
|
{ |
58
|
|
|
return $this->getItem('fullName') ?: ($this->takeVendor()->name . '/' . $this->name); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getSource() |
62
|
|
|
{ |
63
|
|
|
return $this->getItem('source') ?: ('https://github.com/' . $this->takeGoal('github')->name); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getVersion() |
67
|
|
|
{ |
68
|
|
|
return $this->takeGoal('version')->version; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getNamespace() |
72
|
|
|
{ |
73
|
|
|
return $this->getItem('namespace') ?: $this->getPackageManager()->namespace ?: self::defaultNamespace($this->takeVendor()->name, $this->name); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function defaultNamespace($vendor, $package) |
77
|
|
|
{ |
78
|
|
|
return preg_replace('/[^a-zA-Z0-9\\\\]+/', '', $vendor . strtr("-$package", '-', '\\')); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getSrc() |
82
|
|
|
{ |
83
|
|
|
$src = $this->rawItem('src'); |
84
|
|
|
|
85
|
|
|
return isset($src) ? $src : 'src'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getHomepage() |
89
|
|
|
{ |
90
|
|
|
return $this->getItem('homepage') ?: $this->getSource(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getForum() |
94
|
|
|
{ |
95
|
|
|
return $this->getItem('forum') ?: $this->takeVendor()->forum; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getLabel() |
99
|
|
|
{ |
100
|
|
|
return $this->getItem('label') ?: $this->getHeadline() ?: Helper::id2camel($this->name); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getTitle() |
104
|
|
|
{ |
105
|
|
|
return $this->getItem('title') ?: Helper::titleize($this->name); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getHeadline() |
109
|
|
|
{ |
110
|
|
|
return $this->getItem('headline'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getDescription() |
114
|
|
|
{ |
115
|
|
|
return $this->getItem('description'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getRepositoryUrl($file) |
119
|
|
|
{ |
120
|
|
|
return 'https://github.com/' . $this->getFullName() . '/blob/master/' . $file; |
121
|
|
|
} |
122
|
|
|
public function getAuthors() |
123
|
|
|
{ |
124
|
|
|
return $this->getItem('authors') ?: $this->takeVendor()->authors; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Composer for the moment. |
129
|
|
|
* To be changed to get actual Package Manager. |
130
|
|
|
*/ |
131
|
|
|
public function getPackageManager() |
132
|
|
|
{ |
133
|
|
|
return $this->takeGoal('composer'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function hasRequireAny($package) |
137
|
|
|
{ |
138
|
|
|
return $this->hasRequire($package) || $this->hasRequireDev($package); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function hasRequire($package) |
142
|
|
|
{ |
143
|
|
|
$pman = $this->getPackageManager(); |
144
|
|
|
|
145
|
|
|
return $pman && array_key_exists($package, $pman->getConfiguration()->getRequire()); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function hasRequireDev($package) |
149
|
|
|
{ |
150
|
|
|
$pman = $this->getPackageManager(); |
151
|
|
|
|
152
|
|
|
return $pman && array_key_exists($package, $pman->getConfiguration()->getRequireDev()); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.