1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Asset Packagist |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/asset-packagist |
7
|
|
|
* @package asset-packagist |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hiqdev\assetpackagist\registry; |
13
|
|
|
|
14
|
|
|
use Composer\IO\NullIO; |
15
|
|
|
use Composer\Repository\RepositoryManager; |
16
|
|
|
use Fxp\Composer\AssetPlugin\Config\Config; |
17
|
|
|
use Fxp\Composer\AssetPlugin\Repository\AbstractAssetsRepository; |
18
|
|
|
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager; |
19
|
|
|
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter; |
20
|
|
|
|
21
|
|
|
class RegistryFactory |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected static $classes = [ |
27
|
|
|
'bower' => BowerRegistry::class, |
28
|
|
|
'npm' => NpmRegistry::class, |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var AbstractAssetsRepository[] |
33
|
|
|
*/ |
34
|
|
|
public static $registries = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string $type |
38
|
|
|
* @param RepositoryManager $rm |
39
|
|
|
* @return AbstractAssetsRepository|BowerRegistry|NpmRegistry |
40
|
|
|
*/ |
41
|
|
|
public static function getRegistry($type, $rm) |
42
|
|
|
{ |
43
|
|
|
if (!isset(static::$registries[$type])) { |
44
|
|
|
static::$registries[$type] = static::buildRegistry($type, $rm); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return static::$registries[$type]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $type |
52
|
|
|
* @param RepositoryManager $rm |
53
|
|
|
* @return mixed |
54
|
|
|
*/ |
55
|
|
|
protected static function buildRegistry($type, $rm) |
56
|
|
|
{ |
57
|
|
|
$class = static::$classes[$type]; |
58
|
|
|
$rm->setRepositoryClass($type, $class); |
59
|
|
|
|
60
|
|
|
$config = [ |
61
|
|
|
'asset-repository-manager' => self::createAssetRepositoryManager($rm), |
62
|
|
|
'asset-options' => [], |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
return $rm->createRepository($type, $config); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public static function createAssetRepositoryManager($repositoryManager) |
69
|
|
|
{ |
70
|
|
|
$filter = (new \ReflectionClass(VcsPackageFilter::class))->newInstanceWithoutConstructor(); |
71
|
|
|
|
72
|
|
|
return new AssetRepositoryManager(new NullIO(), $repositoryManager, new Config([]), $filter); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|