10
10
11
11
namespace hiqdev \assetpackagist \models ;
12
12
13
- use Composer \Composer ;
14
- use Composer \Factory ;
15
13
use Composer \Package \Link ;
16
14
use Exception ;
17
- use Fxp \Composer \AssetPlugin \Repository \AssetVcsRepository ;
18
15
use hiqdev \assetpackagist \components \Storage ;
19
- use hiqdev \assetpackagist \log \YiiLogIO ;
20
- use hiqdev \assetpackagist \registry \BowerRegistry ;
21
- use hiqdev \assetpackagist \registry \NpmRegistry ;
22
16
use hiqdev \assetpackagist \registry \RegistryFactory ;
23
17
use Yii ;
24
18
use yii \base \Object ;
@@ -33,29 +27,12 @@ class AssetPackage extends Object
33
27
*/
34
28
protected $ _releases = [];
35
29
protected $ _saved ;
36
- /**
37
- * @var AssetVcsRepository|BowerRegistry|NpmRegistry
38
- */
39
- protected $ _registry ;
40
30
41
31
/**
42
32
* @var integer UNIX Epoch timestamp of the latest package update
43
33
*/
44
34
protected $ _updateTime ;
45
35
46
- /**
47
- * @var YiiLogIO
48
- */
49
- protected $ _io ;
50
- /**
51
- * @var Composer
52
- */
53
- protected $ _composer ;
54
- /**
55
- * @var Composer
56
- */
57
- protected static $ _commonComposer ;
58
-
59
36
public static function normalizeName ($ name )
60
37
{
61
38
return strtolower ($ name );
@@ -82,13 +59,12 @@ public function __construct($type, $name, $config = [])
82
59
$ this ->_name = $ name ;
83
60
}
84
61
62
+ /**
63
+ * @return RegistryFactory
64
+ */
85
65
public function getRegistry ()
86
66
{
87
- if ($ this ->_registry === null ) {
88
- $ this ->_registry = RegistryFactory::getRegistry ($ this ->getType (), $ this ->getComposer ()->getRepositoryManager ());
89
- }
90
-
91
- return $ this ->_registry ;
67
+ return Yii::$ app ->get ('registryFactory ' );
92
68
}
93
69
94
70
public function checkType ($ type )
@@ -149,49 +125,6 @@ public function getHash()
149
125
return $ this ->_hash ;
150
126
}
151
127
152
- /**
153
- * @return Composer
154
- */
155
- public static function getCommonComposer ()
156
- {
157
- if (static ::$ _commonComposer === null ) {
158
- static ::$ _commonComposer = (new Factory ())->createComposer (
159
- new YiiLogIO (),
160
- Yii::getAlias ('@composer/composer.json ' ),
161
- false ,
162
- Yii::getAlias ('@composer ' )
163
- );
164
- }
165
-
166
- return static ::$ _commonComposer ;
167
- }
168
-
169
- public function setComposer ($ value )
170
- {
171
- $ this ->_composer = $ value ;
172
- }
173
-
174
- /**
175
- * @return Composer
176
- */
177
- public function getComposer ()
178
- {
179
- if ($ this ->_composer === null ) {
180
- $ this ->_composer = static ::getCommonComposer ();
181
- }
182
-
183
- return $ this ->_composer ;
184
- }
185
-
186
- public function getIO ()
187
- {
188
- if ($ this ->_io === null ) {
189
- $ this ->_io = new YiiLogIO ();
190
- }
191
-
192
- return $ this ->_io ;
193
- }
194
-
195
128
/**
196
129
* findOne.
197
130
*
@@ -219,21 +152,21 @@ public function load()
219
152
220
153
public function update ()
221
154
{
222
- $ repo = $ this ->getRegistry ()->buildVcsRepository ( $ this -> getName () );
223
- $ this ->_releases = $ this ->prepareReleases ($ repo );
155
+ $ pool = $ this ->getRegistry ()->getPool ( );
156
+ $ this ->_releases = $ this ->prepareReleases ($ pool );
224
157
$ this ->getStorage ()->writePackage ($ this );
225
158
$ this ->load ();
226
159
}
227
160
228
161
/**
229
- * @param AssetVcsRepository $repository
162
+ * @param \Composer\DependencyResolver\Pool $pool
230
163
* @return array
231
164
*/
232
- public function prepareReleases ($ repository )
165
+ public function prepareReleases ($ pool )
233
166
{
234
167
$ releases = [];
235
168
236
- foreach ($ repository -> getPackages ( ) as $ package ) {
169
+ foreach ($ pool -> whatProvides ( $ this -> getFullName () ) as $ package ) {
237
170
if ($ package instanceof \Composer \Package \AliasPackage) {
238
171
continue ;
239
172
}
@@ -269,6 +202,9 @@ public function prepareReleases($repository)
269
202
}
270
203
}
271
204
205
+ //Sort before save
206
+ \hiqdev \assetpackagist \components \PackageUtil::sort ($ releases );
207
+
272
208
return $ releases ;
273
209
}
274
210
0 commit comments